一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

JS Timing

使用JS是可以讓函數不直接執行的,而是在過了一個指定的時間間隔后才執行。這就叫做事件事件。
With JavaScript, it is possible to execute some code NOT immediately after a function is called, but after a specified time interval. This is called timing events.
使用JS是可以讓函數不直接執行的,而是在過了一個指定的時間間隔后才執行。這就叫做事件事件。
JavaScript Timing Events
JS時間事件
With JavaScript, it is possible to execute some code NOT immediately after a function is called, but after a specified time interval. This is called timing events.
使用JS是可以讓函數不直接執行的,而是在過了一個指定的時間間隔后才執行。這就叫做事件事件。
It's very easy to time events in JavaScript. The two key methods that are used are:
JS的時間事件是非常簡單的。使用了兩個關鍵的方法:
    * setTimeout() - executes a code some time in the future
      在一些時間后執行代碼
    * clearTimeout() - cancels the setTimeout()
      取消setTimeout() 
Note: The setTimeout() and clearTimeout() are both methods of the HTML DOM Window object.
注意:setTimeout() 和 Timeout() 都是HTML DOM Window 對象的方法。
setTimeout()
Syntax語法
var t=setTimeout("Javascript statement",milliseconds)
The setTimeout() method returns a value - In the statement above, the value is stored in a variable called t. If you want to cancel this setTimeout(), you can refer to it using the variable name.
setTimeout()方法返回一個值 - 在上面的聲明里,值被保存在變量t中。如果你想取消這個setTimeout()可以使用變量名來提出它(用clearTimeout(t))
The first parameter of setTimeout() is a string that contains a JavaScript statement. This statement could be a statement like "alert('5 seconds!')" or a call to a function, like "alertMsg()".
setTomeout()的第一個參數是字符串聲明。它可以像"alert('5 seconds!')"或是調用一個函數像"alertMsg()"
The second parameter indicates how many milliseconds from now you want to execute the first parameter.
第二個參數用來表明從現在開始你希望在多少毫秒后執行第一個參數
Note: There are 1000 milliseconds in one second.
1000毫秒為一秒
Example
舉例
When the button is clicked in the example below, an alert box will be displayed after 5 seconds.
當下面的按鈕被點擊后,每過5秒就會出現一個警告框。
<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>
</body>
</html>
Example - Infinite Loop
無限循環
To get a timer to work in an infinite loop, we must write a function that calls itself. In the example below, when the button is clicked, the input field will start to count (for ever), starting at 0:
要得到一個無限循環的記時器,我們必須寫出一個自我調用的函數。下面的例子,當按鈕按下后,輸入框就會從0開始記數(永遠的)
<html>
<head>
<script type="text/Javascript">
var c=0
var t
function timedCount()
{
document.getElementById('txt').value=c
c=c+1
t=setTimeout("timedCount()",1000)
}
</script>
</head>
<body>
<form>
<input type="button" value="Start count!"
onClick="timedCount()">
<input type="text" id="txt">
</form>
</body>
</html>
clearTimeout()
Syntax語法
clearTimeout(setTimeout_variable)
Example
舉例
The example below is the same as the "Infinite Loop" example above. The only difference is that we have now added a "Stop Count!" button that stops the timer:
下面的例子和上面的“無限循環”差不多。唯一的不同就是我們現在多了一個“停止記數”的按鈕來停止記時器。
<html>
<head>
<script type="text/Javascript">
var c=0
var t
function timedCount()
{
document.getElementById('txt').value=c
c=c+1
t=setTimeout("timedCount()",1000)
}
function stopCount()
{
clearTimeout(t)
}
</script>
</head>
<body>
<form>
<input type="button" value="Start count!"
onClick="timedCount()">
<input type="text" id="txt">
<input type="button" value="Stop count!"
onClick="stopCount()">
</form>
</body>
</html>

JavaScript技術JS Timing,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 久久九九免费视频 | 国产精品酒店视频 | 婷婷四房综合激情五月性色 | 理论片中文字幕在线观看 | 一本大道久久香蕉成人网 | 国产精品亚洲片在线花蝴蝶 | 亚洲激情99 | 青青国产成人久久激情911 | 五月九九 | 亚洲欧美成人综合久久久 | 国产精品嫩草影视在线观看 | 国产精品久久1024 | 久久国产精品超级碰碰热 | 成人免费一区二区三区 | 国产成人禁片在线观看 | 人人爰人人人人人鲁 | 亚洲福利在线视频 | 微拍秒拍99福利精品小视频 | 一区二区免费看 | 欧美黑人粗硬大在线看 | 国产91免费在线观看 | 国产成人精品亚洲77美色 | 丁香综合在线 | 一区卡二区卡三区卡视频 | 国产一区二区三区在线观看免费 | 午夜视频吧 | 成人影院视频 | 激情小说激情图片 | 美女网站色视频 | 国产一区二区在线视频播放 | 色综合社区 | 青青国产成人久久激情911 | 激情欧美一区二区三区中文字幕 | 狠狠色噜噜狠狠狠四色米奇 | 欧美黄一级 | 国产免费叼嘿在线观看 | 97爱爱| 色婷婷免费视频 | 看全色黄大色大片免费视频 | 亚洲精品福利在线观看 | 天天色天天操综合网 |