Myitem1.MyFunc();
Myitem2.MyFunc();
function MyFunc(){
if (okToUpdate){
//we weren't here from anywhere within the last 100 milliseconds
}
}
不幸的是,okToUpdate
变量不会立即更新,所以还需要从功能的前一次调用至少100毫秒要有正确的价值。 如何让MyFunc延迟执行?
Myitem1.MyFunc();
Myitem2.MyFunc();
function MyFunc(){
if (okToUpdate){
//we weren't here from anywhere within the last 100 milliseconds
}
}
不幸的是,okToUpdate
变量不会立即更新,所以还需要从功能的前一次调用至少100毫秒要有正确的价值。 如何让MyFunc延迟执行?
setTimeout(function(){
Myitem1.MyFunc();
},100)
将做的伎俩。如果你准确解释你想要的东西,我可以给你准确的时间码。
此代码可以帮助你
var clrTime=null;
MyFunc(){
clrTime=setTimeout(function(){
if (okToUpdate){
// your code to do
}
},100);
}
使用回调或承诺,将是干净的解决方案。没有一些忙碌的等待超时执行。
我会使用setTimeout()
功能。事情是这样的:
<script>
function myFunction() {
setTimeout(function(){MyFunc()},100);
}
</script>
<body onload="myFunction()">
</body>
使用的setTimeout()函数 – Anuj