Javascript 添加超时功能以显示cookie的模式
我已经成功地使用这个脚本设置了一个jquery 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
<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();
},延误);
}
});