Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.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 如何使模态窗口只显示一次?_Javascript_Jquery_Window_Modal Dialog - Fatal编程技术网

Javascript 如何使模态窗口只显示一次?

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

如何将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
    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(){ ... });