使用setInterval 函数。
这将在一段时间后继续调用该函数。
示例:
var myFunction = function () {
//do something
};
setInterval(myFunction, 1000)
在本例中,它将每 1000 微秒调用一次myFunction。
关键:
1000 毫秒 = 1 秒
您也可以使用脚本取消setInterval:
//create an variable for the setInterval
var intervalId = setInterval(myFunction, 2500);
//That is 2.5 seconds
//Now to cancel the interval:
clearInterval(intervalId);
使用clearInterval(); 停止间隔。
在() 中输入要停止的区间名称。
调用多个函数或做某事:
要一次调用多个函数或执行其他操作,请使用以下命令:
var intervalId = setInterval(function () {
//put whatever you want here, I'll put some examples
callAFunction();
inputFunction("123Example...");
alert("Hello!");
//Not a function, just as I said, you can do whatever you want here
console.log("setInterval Is great"); //Not a function!!!!!!!!!!!!!
//This is a comment
/*
This is
another
*/
functionCall();
//here is the end of this variable
}, 100); //the number is the amount of ms after it loops again
你看到了吗?这非常有用!
告诉我如果我说了你不想做的话。
^_^