[英]Change Time of setInterval on Button Click
I want to know if it is possible to change the interval time of a setIinterval
on the click of a button. 我想知道是否可以在单击按钮时更改
setIinterval
的间隔时间。 The problem I'm currently having is that setInterval
, which refreshes the table and ruins the effect of changing button on it. 我目前遇到的问题是
setInterval
,它刷新了表并破坏了更改按钮的效果。
I would like to know if this can be changed, and would appreciate your help. 我想知道这是否可以改变,并感谢您的帮助。
This is the function with setInterval: 这是setInterval的函数:
$.ajax({
type:"POST",
url:"php/recibeDos.php",
cache:false,
success:function(html){
$("#pizarra").html(html);
}
});
setInterval(refresh_table, 3000);
$("#edit-trigger").on('click',function(){
$(this).toggleClass("btn btn-editar");
$(this).toggleClass("btn btn-default");
$( ".btnBorrar" ).toggle(150);
$('.edita-paciente').toggle(250);
});
是的,使用clearInterval(tId)
(但首先为这个区间分配一个id,如下所示: var tId = setInterval(refresh_table, 3000);
I don't think you can change the interval time. 我不认为你可以改变间隔时间。 However, maybe you could make a function, which cancel the current interval and creates new one with the desired parameters.
但是,也许您可以创建一个函数,它取消当前间隔并创建具有所需参数的新间隔。
setInterval returns the intervalId, which you must give as parameter to clearInterval() -function. setInterval返回intervalId,您必须将其作为参数提供给clearInterval()-function。
https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval#Return_value https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval#Return_value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.