如何将以下脚本作为函数?

时间:2018-06-02 09:23:39

标签: jquery

我需要将脚本变成一个函数

var iterations = document.getElementById('test').innerHTML;
var count = 0;
var button = document.getElementById("click");
var myInterval = setInterval(function test(){ 
if (count >= iterations) {
clearInterval(myInterval);
}else{
count++;
button.click();}

我尝试但没有工作:

function test(){
var iterations
....
button.click();}}

1 个答案:

答案 0 :(得分:0)

尝试使用以下代码

var myInterval = setInterval(test, 0);
function test() {
    var iterations, count;
    ...........do iterations with `count`.....
    if (count >= iterations) {
        clearInterval(myInterval);
    } else {
        count++;
        button.click();
    }
}