JS正則表達式
//js 正則表達式創建
var reg1 = new RegExp("^[a-zA-Z][a-zA-Z0-9_]{5,11}$")
var s1 = "hello"
reg1.test(s1) //false //匹配
var s2 = "helloworld"
reg1.test(s2) //true
reg1.test() //true 啥都不寫 居然是true 相當于 reg1.test("undifined")
//匹配元素
var s = "hello world"
s.match(/o/) //["o", index: 4, input: "hello world", groups: undefined] 匹配1個
s.match(/o/g) //["o", "o"] //全局匹配 匹配一次當前索引就往后走到匹配的元素的后面
//找到元素的第一個位置
s.search(/e/) //1
s.search(/o/) //4
//分割
s.split(/o/) // ["hell", " w", "rld"]
s.split(/o/g) // ["hell", " w", "rld"]
//替換 replace
var s = "hello world"
s.replace(/o/,'x') // "hellx world"
//替換不區分大小寫
var s = "Tom is on the table"
s.replace(/t/gi,'B') //"Bom is on Bhe Bable"
JS Math方法
Math.abs(-10) //10
Math.exp(10) //22026.465794806718
Math.log(10) //2.302585092994046
Math.floor(2.5) //2
Math.max(2,3) //3
Math.min(2,5) //2
Math.pow(2,3) //8
Math.random()
Math.round(4.5) //4 在python中 print(round(4.5)) =4 print(round(5.5)) = 6
Math.sin(Math.PI/6) //正弦
BOM 模型&DOM 模型
-
BOM 瀏覽器對象模型
-
windows對象
var a = 100 window.a //100 window.innerHeight //500 瀏覽器窗口和寬度 window.innerWidth //1600window.open() //打開新的網頁//navigator 子對象 navigator.userAgent //獲取客戶端 (瀏覽器)信息//screen 屏幕對象 screen.availWidth // 可用的屏幕寬度 screen.availHeight // 可用的屏幕高度//history 對象 history.forward() history.back()//location 對象 window.location.href //獲取當前頁面的url window.location.href="www.baidu.com" //跳轉到百度 window.location.reload() //刷新頁面//window對象里的彈框 window.alert("hello world!") window.confirm("你確定么?") window.prompt("輸入的你的名字","名字")//計時器 setTimeout() var timer = window.setTimeout(function(){confirm(" 你確定?")},3000) //js語句寫在function內 window.clearTimeout(timer) //清除計時器window.setInterval(function(){alert("aaa")},3000) //定時任務 window.clearInterval(29895) -
DOM 文檔對象模型
浙公網安備 33010602011771號