browser object model
windiw是全局对象,它有一些常见的方法
alert()
confirm()
window.alert(“hello world”)
<script>var t = window.confirm("要不要")console.log(t)</script>
2.4.1、screen(获取客户端关于屏幕的信息)
#获取页面宽度var screenWidth = window.screen.availWidth;console.log(screenWidth)
#获取可视区域的宽度var viewWidth = document.body.clientWidth;console.log(viewWidth)
2.4.2、location
#跳转到页面location.href
var btn = document.getElementById("btn");btn.onclick = function(){console.log(location.href)}
2.4.3、 history
#返回上一个页面history.back();var btn = document.getElementById("btn");btn.onclick = function(){history.back();}
#返回下一个页面history.forward();var btn = document.getElementById("btn");btn.onclick = function(){history.forward();}
2.4.4、setTimeout/ setInterval(超时调用/间歇调用)
<script>// 超时调用// 间隔一段时间触发,只会触发一次setTimeout(function(){console.log("hello world")},2000)// setInterval() 间歇调用// 每隔一段时间就会触发setInterval(function(){console.log("1")},1000)</script>
2.4.5、递归
函数调用函数自身,就叫递归
function show(){setInterval(function() {console.log(1)show();},1000)}show()
