• js 页面定时刷新


    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 ,即使页面完全刷新,本地的存储不变,然后新页面依照这个存储进行判断

  • 相关阅读:
    点分治 (等级排) codeforces 321C
    树上点分治 poj 1741
    判断点在直线的左侧还是右侧
    树的重心
    链式前向星
    树上点的分治
    构造 素数
    二进制 + 模拟
    枚举 + 三分 (游标)
    枚举 + 三分
  • 原文地址:https://www.cnblogs.com/tingfengqieyu/p/6704993.html
Copyright © 2020-2023  润新知