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 //1600
window.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 文档对象模型