Javascript 如何使模态窗口只显示一次?
如何将cookie附件添加到脚本?我浏览了这个网站,试图放置代码,但没有任何效果 这是我的代码:Javascript 如何使模态窗口只显示一次?,javascript,jquery,window,modal-dialog,Javascript,Jquery,Window,Modal Dialog,如何将cookie附件添加到脚本?我浏览了这个网站,试图放置代码,但没有任何效果 这是我的代码: $(document).ready(function() { //select all the a tag with name equal to modal $('a[name=modal]').click(function(e) { //Cancel the link behavior e.preventDefault(); //Get the A tag v
$(document).ready(function() {
//select all the a tag with name equal to modal
$('a[name=modal]').click(function(e) {
//Cancel the link behavior
e.preventDefault();
//Get the A tag
var id = $(this).attr('href');
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();
//Set height and width to mask to fill up the whole screen
$('#mask').css({'width':maskWidth,'height':maskHeight});
//transition effect
$('#mask').fadeIn(1000);
$('#mask').fadeTo("slow",0.8);
//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
//Set the popup window to center
$(id).css('top', winH/2-$(id).height()/2);
$(id).css('left', winW/2-$(id).width()/2);
//transition effect
$(id).fadeIn(2000);
});
//if close button is clicked
$('.window .close').click(function (e) {
//Cancel the link behavior
e.preventDefault();
$('#mask, .window').hide();
});
//if mask is clicked
$('#mask').click(function () {
任何人都可以帮助我添加cookie段,以便窗口仅打开一次/user,这将非常好。您可以使用
one()将事件附加到上,单击仅一次。
:
我不认为这是OP想要的,因为提到使用饼干。刷新页面后,模式窗口将再次打开。没错,但问题有点混乱,但这可能会有所帮助,我不知道。。
$('a[name=modal]').one('click', function(){ ... });