当前位置: 代码迷 >> Java Web开发 >> js函数调用解决思路
  详细解决方案

js函数调用解决思路

热度:77   发布时间:2016-04-17 12:22:08.0
js函数调用
我想通过setTimeout方法来控制js某个函数的执行次数,当某个js函数的执行超过指定次数时,自动跳转并执行其他函数。
如:setTimeout(ourmove,1),ourmove是我的js函数,然后就不知道怎么写了,求各位高手帮忙!谢谢!

------解决方案--------------------
Java code
var count = 0;var toCount = 10;//指定次数function ourmove(){    if (count < toCount) {        count++;        //ourmove函数要执行的代码    } else {        anotherFunction();    }}function anotherFunction() {...}setInterval(ourmove,1);
------解决方案--------------------
定义一个int变量,js函数每执行一次加一,然后用变量作判断不就行了吗。
------解决方案--------------------
JScript code
var count = 0;var toCount = 10;//指定次数function ourmove(){    if (count < toCount) {        count++;        //ourmove函数要执行的代码    } else {        clearInterval(itid);         anotherFunction();    }}function anotherFunction() {...}var itid = setInterval(ourmove,1);
  相关解决方案