[英]Turn on / off auto-refresh
I have a page that may or may not refresh itself. 我的页面可能会刷新也可能不会刷新。
And I have a checkbox that will control it, but I have no idea how to implement it. 我有一个可以控制它的复选框,但是我不知道如何实现它。
I've tried to use <asp:Timer>
component, but it doesn't work. 我试图使用
<asp:Timer>
组件,但是它不起作用。
Using setInterval
/ setTimeout
from JS, I can't achieve this. 使用JS中的
setInterval
/ setTimeout
,我无法实现。
My question is - What .NET component or JS/Jquery attribute I have to use to achieve this? 我的问题是-我必须使用哪个.NET组件或JS / Jquery属性来实现这一目标?
You can use this if you are using jQuery: 如果使用的是jQuery,则可以使用以下代码:
$(function(){
$('#timercheck').on('change', function () {
if ($(':checked').length > 0) {
clearInterval(timer);
}
});
var timer = setInterval(function(){
window.location.reload();
},5000);
});
Here #timercheck
is the id of checkbox. #timercheck
是复选框的ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.