点击按钮后弹出提示信息,几秒之后跳转到某页面

雨燕双飞 提交于 2020-12-09 06:06:19
js代码
//clearTimeout的作用是清除setTimeout的方法.或者说注销setTimeout方法,让setTimeout方法停止或无法运行.
    // 使用clearTimeout时必须指定一个参数.该参数是setTimeout返回的ID值.也就是说当你使用setTimeout时.必须要为setTimeout指定一个返回的id值.随意指定一个变量

    // set_id=setTimeout(fun,1000);
    // function fun(){
    $(document).on("click", ".clickme", function (event) {
        $(".read-later-alert").show();
        set_id = setTimeout(function () {
            $(".read-later-alert").hide()
            window.location.href='../addTower.html'
        }, 3000);
       
        //  $(".read-later-alert").hover(function(){
        //      clearTimeout(set_id);
        //  },function(){
        //      $(this).hide();
        //  })
    });
    
    // }
View Code
html代码
<button class="clickme">点我啊</button>

    <div class="read-later-alert" style="display:none">31465465</div>
View Code
css代码
   .read-later-alert {
            position: absolute;
            top: 50%;
            left: 40%;
            height: 40px;
            background: rgba(48, 48, 48, 0.8);
            padding: 10px;
            -moz-border-radius: 7px;
            -webkit-border-radius: 7px;
            color: #fff;
            position: fixed;
            display: none;
            text-align: center;
            z-index: 9999;
        }
View Code

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!