首页 js中的定时器,延迟器(Timer, delay device in JS)

js中的定时器,延迟器(Timer, delay device in JS)

举报
开通vip

js中的定时器,延迟器(Timer, delay device in JS)js中的定时器,延迟器(Timer, delay device in JS) js中的定时器,延迟器(Timer, delay device in JS) Timer collection in JavaScript Timer: (retarder) Used to specify the execution of a program at a specified time. SetTimeout (): (version 1) Format: [object name as setTimeout ...

js中的定时器,延迟器(Timer, delay device in JS)
js中的定时器,延迟器(Timer, delay device in JS) js中的定时器,延迟器(Timer, delay device in JS) Timer collection in JavaScript Timer: (retarder) Used to specify the execution of a program at a specified time. SetTimeout (): (version 1) Format: [object name as setTimeout timer ("< expression >", MS) Function: execute < expressions > once. SetTimeout (code, time) Example: setTimeout ("alert" (test to see if it has been delayed); "10000) Where code is a Javascript instruction, indicating events after the delay. Time is how long after the delay, 1000 represents 1 second. ClearTimeout (): terminates the timer Format: ClearTimeout (timer object name) SetInterval (): (version 1.2) Format: [object name as setInterval timer ("< expression >", MS) Function: repeats < expressions > until the window, frame is closed or clearInterval is executed. ClearInterval (): terminates the timer Format: ClearInterval (timer object name) Example 1: Residence time: 0 seconds Example 2: Article quoted from: SetInterval and clearInterval explain on, 07 October, at p.m. on Tuesday, 10 05:06clearInterval, similar to JS's clearTimeout The time interval can be created with the setInterval command and terminated with the clearInterval command. The parameters used by setInterval are in two formats. In the first format, the parameter you pass to setInterval can be a function name, a period of interval, and some parameters passed to the previous function. When the setInterval is running, it passes the parameters listed to the specified function in accordance with the specified time interval until you call clearInterval to terminate it. The relevant demonstration code is as follows: Function updateStockPrices (whichStock) { Code here / / Update Trace ('Updating, prices, for,'+whichStock); } StockInterval = setInterval (updateStockPrices, 1000, Stratford, Flash, Products); SetInterval comprehensive introduction The function of the setInterval action is to call the function, method, or object at regular intervals when the animation is played. You can use this action to update variables from the database or update time display. The syntax for the setInterval action is as follows: SetInterval (function, interval[, arg1, arg2,..., argn]) SetInterval (object, methodName, interval[, arg1, arg2,.....Argn]) The first format is the default syntax for the setInterval function in the standard action panel, and the second is the method used in expert mode actions. The parameter function is a function name, or a reference to an anonymous function. The object parameter specifies the object to be derived from the Object object. MethodName sets the method to call in the object parameter. Interval sets the time between two calls to function or methodName, in milliseconds. The following arg1, etc., are optional parameters that are used to formulate arguments passed to function or methodName. SetInterval it sets the time interval smaller than the animation frame rate (such as 10 frames per second, equivalent to 100 milliseconds), and calls the function as close as possible to the interval interval. And you must use the updateAfterEvent action to ensure that the screen is refreshed at sufficient frequency. If the interval is larger than the animation frame rate, only calls are entered at each of the playback heads to reduce the impact of each refresh screen. The following example calls an anonymous function every second. SetInterval (function ({trace) ("every 1 seconds, I will display a")}, 1000); / / function here () {} is not a function name Function. An anonymous function, followed by 1000 intervals, in milliseconds. The following example shows how to run with parameters. Function, show1 () { Trace ("I'll show it every other second"); } Function show2 (STR) { Trace (STR); } SetInterval (show11000); SetInterval (show22000, "I'll show it every 2 seconds"); The setInterval method of the function has been introduced above. Next, we will introduce the setInterval method of objects. First, write an example of how setInterval calls an object in an action that does not need to pass arguments. Myobj=new (Object); / / create a new object Myobj.interval=function) { Trace ("I'll show it every other second"); Methods}// create objects. SetInterval (myobj, interval, 1000); / / set the time interval of the call object method. Next describes how to pass arguments. In fact, arguments and functions pass the same parameters. Myobj=new, Object (); Myobj.interval-function (STR) { Trace (STR); } SetInterval (myobj, "interval", "2000"), "every 2 seconds I show it"; Be careful。 To call methods defined for objects, you must use second syntax formats in the expert mode. In that case, let's make a dynamic display of time. You can do it in the following code. SetInterval (show, 1000); Function, show () { Time=new, Date (); Hour=time.getHours (); Minu=time.getMinutes (); Sec=time.get.Seconds (); Datetime=hour: "minu": "sec."; }// where datetime is a dynamic variable name text box. In this way, setInterval this method, we should learn very well. Now, we learn clearInterval. The action of the clearInterval action is to make clear the call to the setInterval function, whose syntax is as follows clearInterval (intervalid); intervalid is the object returned after calling the setInterval function. Here's a simple example. Function, show () { Trace ("I'll show it every other second"); } Var sh; Sh=setInterval (show, 1000); ClearInterval (SH);
本文档为【js中的定时器,延迟器(Timer, delay device in JS)】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_591137
暂无简介~
格式:doc
大小:26KB
软件:Word
页数:7
分类:生活休闲
上传时间:2017-09-27
浏览量:15