Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用相同按钮设置间隔和清除间隔_Javascript_Jquery_Html - Fatal编程技术网

Javascript 使用相同按钮设置间隔和清除间隔

Javascript 使用相同按钮设置间隔和清除间隔,javascript,jquery,html,Javascript,Jquery,Html,嘿,我只是想知道是否只有一个按钮就可以让我离开setInterval和clearInterval var检查存在; 函数checkOn(){ checkOff(); checkExist=setInterval(函数(){ if($('#advert').css('display')=='block') $('statcontinue')。触发器('click'); },1000);//检查速度 } 函数checkOff(){ if(checkExist!==null){ clearInter

嘿,我只是想知道是否只有一个按钮就可以让我离开setInterval和clearInterval

var检查存在;
函数checkOn(){
checkOff();
checkExist=setInterval(函数(){
if($('#advert').css('display')=='block')
$('statcontinue')。触发器('click');
},1000);//检查速度
}
函数checkOff(){
if(checkExist!==null){
clearInterval(检查存在);
checkExist=null;
}
}

跳过上的统计信息

跳过Stats Off
验证
checkExist
是否为空,以执行以下操作:

var checkExist=null;
函数切换_check(){
clearInterval(检查存在);
if(checkExist!==null){
checkExist=null;
}否则{
checkExist=setInterval(函数(){
if($('#advert').css('display')=='block')
$('statcontinue')。触发器('click');
console.log('tricked!');
},1000);//检查速度
}
}


跳过
上的统计信息我做了一个快速的变通方法,添加了一个开关方法,检查
checkExist
是否为空

const checkExist=null;
常量checkOn=()=>{
checkExist=setInterval(函数(){
if($('#advert').css('display')=='block')
$('statcontinue')。触发器('click');
},1000);//检查速度
};
常量checkOff=()=>{
if(checkExist!==null){
clearInterval(检查存在);
checkExist=null;
}
};
常量检查开关=()=>{
!checkExist?checkOn():checkOff();
};

点击我