browser object model
windiw是全局对象,它有一些常见的方法
alert()
confirm()
window.alert(“hello world”)

  1. <script>
  2. var t = window.confirm("要不要")
  3. console.log(t)
  4. </script>

2.4.1、screen(获取客户端关于屏幕的信息)

  1. #获取页面宽度
  2. var screenWidth = window.screen.availWidth;
  3. console.log(screenWidth)
  1. #获取可视区域的宽度
  2. var viewWidth = document.body.clientWidth;
  3. console.log(viewWidth)

2.4.2、location

  1. #跳转到页面
  2. location.href
  1. var btn = document.getElementById("btn");
  2. btn.onclick = function(){
  3. console.log(location.href)
  4. }

2.4.3、 history

  1. #返回上一个页面
  2. history.back();
  3. var btn = document.getElementById("btn");
  4. btn.onclick = function(){
  5. history.back();
  6. }
  1. #返回下一个页面
  2. history.forward();
  3. var btn = document.getElementById("btn");
  4. btn.onclick = function(){
  5. history.forward();
  6. }

2.4.4、setTimeout/ setInterval(超时调用/间歇调用)

  1. <script>
  2. // 超时调用
  3. // 间隔一段时间触发,只会触发一次
  4. setTimeout(function(){
  5. console.log("hello world")
  6. },2000)
  7. // setInterval() 间歇调用
  8. // 每隔一段时间就会触发
  9. setInterval(function(){
  10. console.log("1")
  11. },1000)
  12. </script>

2.4.5、递归

函数调用函数自身,就叫递归

  1. function show(){
  2. setInterval(function() {
  3. console.log(1)
  4. show();
  5. },1000)
  6. }
  7. show()