本文Demo为大家分享了js实现点击弹窗弹出登录框的具体代码,供大家参考,具体内容如下,因为某个程序需要做一个弹窗代码,用了Layui弹窗,但是想实现只弹出一次,就有了一下代码,记录一下,防止忘记~ Layui弹窗代码可参考Layui文档来自行开发,Layui文档:http://layui.xmnets.cn/  #### Demo1: 用cookie记录下,访问过24小时内就不弹,不过是居于浏览器的,不是居于ip,客户端删除cookie也是会继续弹的。 ```php window.onload = function () { //================ var s = document.cookie; if (s.indexOf('myad=1') != -1) return; //存在cookie退出下面代码的执行 var d = new Date(); d.setHours(d.getHours() + 24); //有效期24小时 document.cookie = 'myad=1;expires='+d.toGMTString();//设置cookie //================ /*自己弹窗代码*/ } ``` #### Demo2: 指定日期前,只弹一次,后面不再弹。 ```php $(document).ready(function(){ showSuspend(); }); function setCookie(cookiename, value, expire) { window.document.cookie = cookiename + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString())) + ";path=/";; } function getCookie(cookiename) { var search = cookiename + "="; if (window.document.cookie.length > 0) { offset = window.document.cookie.indexOf(search); if (offset != -1) { offset += search.length; end = window.document.cookie.indexOf(";", offset) if (end == -1) end = window.document.cookie.length; return unescape(window.document.cookie.substring(offset, end)); } } return ""; } var end = new Date('2015-09-03 23:59:59'); function register(cookiename) { setCookie("zhezhao", cookiename, end); } function showSuspend() { if(new Date().getTime() < end.getTime()){ var c = getCookie("zhezhao"); if (c != null && c != "") { return; } register("93"); $("#zhezhaoDiv").show(); } } ``` 我的博客即将同步至腾讯云开发者社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=22f85q1gpw9w8 Last modification:October 22, 2022 © Allow specification reprint Like 3 If you think my article is useful to you, please feel free to appreciate
One comment
您好~我是腾讯云开发者社区运营,关注了您分享的技术文章,觉得内容很棒,我们诚挚邀请您加入腾讯云自媒体分享计划。完整福利和申请地址请见:https://cloud.tencent.com/developer/support-plan
作者申请此计划后将作者的文章进行搬迁同步到社区的专栏下,你只需要简单填写一下表单申请即可,我们会给作者提供包括流量、云服务器等,另外还有些周边礼物。