码迷,mamicode.com
首页 > Web开发 > 详细

js 页面定时刷新

时间:2017-04-13 17:57:44      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:art   定时刷新   log   cli   clear   checkbox   cal   item   oca   

html

           <label class="am-switch am-switch-lg">
                <input type="checkbox" id="check_is_f">
                <span class="am-switch-checkbox"></span>
            </label>
            定时刷新

js

//定时刷新
is_f = localStorage.getItem("is_f");
if(is_f == 2){
    $(‘#check_is_f‘).attr("checked", true);
    tf = setTimeout(‘myrefresh()‘,5000); //指定秒刷新一次
}




$(‘.am-switch input[type=checkbox]‘).on(‘click‘,function(){
    if($(this).is(‘:checked‘)){
        localStorage.setItem("is_f",2);
        tf = setTimeout(‘myrefresh()‘,5000); //指定秒刷新一次
    }else{
        clearTimeout(tf); //取消自动刷新
        localStorage.setItem("is_f",0);
    }
})

function myrefresh(){
window.location.reload();
}

效果:复选框勾中,页面开始每五秒刷新,取消勾中,刷新停止

主要是利用了本地存储 localStorage ,即使页面完全刷新,本地的存储不变,然后新页面依照这个存储进行判断

js 页面定时刷新

标签:art   定时刷新   log   cli   clear   checkbox   cal   item   oca   

原文地址:http://www.cnblogs.com/tingfengqieyu/p/6704993.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!