setInterval设置停止和循环

var timesRun = 0;
var interval = setInterval(function(){
timesRun += 1;
if(timesRun === 60){
clearInterval(interval);
}
//do whatever here..
}, 2000);



var startTime = new Date().getTime();
var interval = setInterval(function(){
if(new Date().getTime() - startTime > 60000){
clearInterval(interval);
return;
}
//do whatever here..
}, 2000);


var interval = setInterval(function(){
    timesRun += 1;
    var textNode = $('input[type="radio"][name="radioName'+questionNo+'"]:checked').parent().parent().find('input[type="text"]');
    console.log(textNode.val());
    if(textNode.val()  == '' || textNode.val() == undefined){//当节点没有值或者还未在页面上生成,则赋值
        console.log(textNode.length);
        textNode.val(inputValue);
    }else {//已经有值了,则清除停止
        clearInterval(interval);
    }
}, 500);

你可能感兴趣的:(前端)