简体   繁体   中英

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.

Using setInterval / setTimeout from JS, I can't achieve this.

My question is - What .NET component or JS/Jquery attribute I have to use to achieve this?

You can use this if you are using 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.

Demo @ Fiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM