Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 添加超时功能以显示cookie的模式_Javascript_Jquery_Cookies_Modal Dialog_Zurb Reveal - Fatal编程技术网

Javascript 添加超时功能以显示cookie的模式

Javascript 添加超时功能以显示cookie的模式,javascript,jquery,cookies,modal-dialog,zurb-reveal,Javascript,Jquery,Cookies,Modal Dialog,Zurb Reveal,我已经成功地使用这个脚本设置了一个jquery cookie,它向站点访问者显示一个显示模式,但每天只显示一次 <script type="text/javascript"> $(document).ready(function(){ // if the cookie doesn't exist create it and show the modal if ( ! $.cookie('hereToday') ) { // creat

我已经成功地使用这个脚本设置了一个jquery cookie,它向站点访问者显示一个显示模式,但每天只显示一次

<script type="text/javascript">
$(document).ready(function(){
        // if the cookie doesn't exist create it and show the modal
        if ( ! $.cookie('hereToday') ) {

        // create the cookie. Set it to expire in 1 day
        $.cookie('hereToday', true, { expires: 1 });

        //call the reveal modal
        $('#subscribe').reveal();
    }
});
</script>

$(文档).ready(函数(){
//如果cookie不存在,则创建它并显示模式
如果(!$.cookie('hereToday')){
//创建cookie。将其设置为1天后过期
$.cookie('hereToday',true,{expires:1});
//调用显示模式
$(“#订阅”).discover();
}
});
如何向脚本中添加超时函数,以便在触发模式之前增加几秒钟的延迟?

只需使用setTimeout

setTimeout(function() {
    $('#subscribe').reveal();
},5000);

Modal将在5秒后调用。

您必须使用,
setTimeout
函数:

<script type="text/javascript">
$(document).ready(function(){
        // if the cookie doesn't exist create it and show the modal
        if ( ! $.cookie('hereToday') ) {

        // create the cookie. Set it to expire in 1 day
        $.cookie('hereToday', true, { expires: 1 });

        //call the reveal modal
        var delay=5000; //in ms, this would mean 5 seconds
        setTimeout(function(){
            $('#subscribe').reveal();
        },delay);
    }
});
</script>

$(文档).ready(函数(){
//如果cookie不存在,则创建它并显示模式
如果(!$.cookie('hereToday')){
//创建cookie。将其设置为1天后过期
$.cookie('hereToday',true,{expires:1});
//调用显示模式
var delay=5000;//以毫秒为单位,这意味着5秒
setTimeout(函数(){
$(“#订阅”).discover();
},延误);
}
});