浏览器对象模型(BOM)

 1.
A.定义:

setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式。

B:

SetTimeout(代码/函数,时间)--->指定时间后,调用函数表达式

  ClearTimeout(SetTimeout ID值)---清楚SetTimeout()方法

eg:(W3C javaScript window)

<html>
<head>
<script type="text/javascript">
function timedMsg()
{
var t=setTimeout("alert('5 seconds!')",5000)
}
</script>
</head>

<body>
<form>
<input type="button" value="Display timed alertbox!"
onClick="timedMsg()">
</form>
<p>Click on the button above. An alert box will be
displayed after 5 seconds.</p>
</body>

</html>

2.
A.定义:

setInterval() 方法可按照指定的周期(以毫秒计)来调用函数或计算表达式。

setInterval() 方法会不停地调用函数,直到 clearInterval() 被调用或窗口被关闭。由 setInterval() 返回的 ID 值可用作 clearInterval() 方法的参数。



B:

SetInterval(代码/函数,时间)--->指定周期后,调用函数表达式

ClearInterval(SetTimeout ID值)---清楚SetTimeout()方法

eg:(W3C javaScript window)

<html>
<body>

<input type="text" id="clock" size="35" />
<script language=javascript>
var int=self.setInterval("clock()",50)
function clock()
  {
  var t=new Date()
  document.getElementById("clock").value=t
  }
</script>
</form>
<button onclick="int=window.clearInterval(int)">
Stop interval</button>

</body>
</html>

3.

ScrollTo

eg:

function sto(){

     window,scrollTo(0,0);-----把内容滚动指定的坐标。

}

ScrollBy

eg:

function sby(){

     window,scrollBy(0,100);-----相对于当前滚动条的位置移动(内容滚动指定的像素值)。

}


4.

累加计时

var a=0;
var t=setInterval(function(){

        a=a+1;
        console.log(a);
},2000);
function sto(){
        clearInterval(t)
      
}

<input typr="button" value="停止" onclick="sto()"/>

原文地址:https://www.cnblogs.com/1039595699TY/p/5495903.html