BOM操作写法实例
瀏覽器相關信息
// 瀏覽器信息 navigator.userAgent // Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36 // 運行瀏覽器的操作系統平臺 navigator.platform // MacIntel瀏覽記錄歷史
// 前進 history.forward() // 后退 history.back()url 信息
頁面跳轉
// 當前頁面會記入瀏覽記錄歷史 location.href = 'http://www.baidu.com' // 當前頁面不會記入瀏覽記錄歷史 location.replace('http://www.baidu.com')頁面重新加載
location.reload()獲得當前 url 的信息
// 假設當前 url 是 http://192.168.31.194:8000/jquery/index.html?a=3&c=aa#blocation.href // 完整的url location.hostname // 192.168.31.194 location.host // 192.168.31.194:8000 location.port // 8000 location.protocol // http: location.search // ?a=3&c=aa location.hash // #b location.pathname // /jquery/index.html全局對象
信息彈出框
alert('你很帥!')確認彈出框
var isReady = confirm('準備好來嗎?') if (isReady) {} else {}輸入信息彈出框
var name = prompt('請輸入你的名字') console.log(name)打開一個新窗口
open('http://baidu.com') // 改變某個窗口的 url open('http://baidu.com', 'a') open('http://youku.com', 'a') // 上面窗口的地址會從 百度 變成 優酷的過段時間后執行
// 1 秒后執行 setTimeout(function() { // doSth }, 1000)每隔一段時間執行
var i = 1 // 每隔 1 秒后執行 var runId = setInterval(function(){ console.log(i++) if(i >= 10) { clearInterval(runId) // 停止執行 } }, 1000)屏幕每次刷新時執行
一般是渲染一些 UI。
var targetEl = document.querySelector('.tar') var res var isStop var runId = requestAnimationFrame(function(){ targetEl.text(res) if(isStop) { cancelAnimationFrame(runId) } })在控制臺輸出信息
console.log('日志信息') console.warn('警告信息') console.info('普通信息') console.error('錯誤信息') console.log('1+2 = %d', 3) var person = {name: 'Joel', gender: '男'} console.log('名字:%s,性別:%s', person.name, person.gender)?
轉載于:https://www.cnblogs.com/liucaixia/p/6142273.html
總結
- 上一篇: 在asp.net中如何自己编写highc
- 下一篇: 20161207py学习笔记