JavaScript 显示 none 不起作用,而 cookie



Live site- http://www.uposonghar.com/test/test_popup.html

我添加了带有该弹出窗口的JavaScript cookie,因此如果有人单击"如果不想再次看到此内容,请单击此处!"按钮,则将存储cookie,如果存储了cookie,则弹出窗口将不会为他/她出现。

一旦我点击成功存储的按钮cookie,popup(id-myModal)就会消失,但弹出bg/overlay(id- reveal-modal-bg)出现。 我添加了该代码,但这不起作用-

if(getCookie('abc')=="def" && document.getElementById('myModal'))
   document.getElementById('myModal').style.display="none";
   document.getElementById('reveal-modal-bg').style.display="none";

js页面上有一个css,也许它会覆盖我的display:none display:block - http://www.uposonghar.com/test/jquery.reveal.js

js页面的代码-

if(options.animation == "none") {
                    modal.css({'visibility' : 'visible', 'top':$(document).scrollTop()+topMeasure});
                    modalBG.css({"display":"block"});   
                    unlockModal()               
                }

完整代码-

<script type="text/javascript">
        function setCookie(c_name,value,exdays)
        {
        var exdate=new Date();
        exdate.setDate(exdate.getDate() + exdays);
        var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
        document.cookie=c_name + "=" + c_value + ";path=/";
        }
        function getCookie(c_name)
        {
        var c_value = document.cookie;
        var c_start = c_value.indexOf(" " + c_name + "=");
        if (c_start == -1)
          {
          c_start = c_value.indexOf(c_name + "=");
          }
        if (c_start == -1)
          {
          c_value = null;
          }
        else
          {
          c_start = c_value.indexOf("=", c_start) + 1;
          var c_end = c_value.indexOf(";", c_start);
          if (c_end == -1)
          {
        c_end = c_value.length;
        }
        c_value = unescape(c_value.substring(c_start,c_end));
        }
        return c_value;
        }

        if(getCookie('abc')=="def" && document.getElementById('myModal'))
        document.getElementById('myModal').style.display="none";
        document.getElementById('reveal-modal-bg').style.display="none";
</script>

你能把jquery.reveal.js中的javascript改成

                if(options.animation == "fadeAndPop" && getCookie('abc')!="def") {
                    modal.css({'top': $(document).scrollTop()-topOffset, 'opacity' : 0, 'visibility' : 'visible'});
                    modalBG.fadeIn(options.animationspeed/2);
                    modal.delay(options.animationspeed/2).animate({
                        "top": $(document).scrollTop()+topMeasure + 'px',
                        "opacity" : 1
                    }, options.animationspeed,unlockModal());                   
                }
                if(options.animation == "fade" && getCookie('abc')!="def") {
                    modal.css({'opacity' : 0, 'visibility' : 'visible', 'top': $(document).scrollTop()+topMeasure});
                    modalBG.fadeIn(options.animationspeed/2);
                    modal.delay(options.animationspeed/2).animate({
                        "opacity" : 1
                    }, options.animationspeed,unlockModal());                   
                } 
                if(options.animation == "none" && getCookie('abc')!="def" ) {
                            modal.css({'visibility' : 'visible', 'top':$(document).scrollTop()+topMeasure});
                            modalBG.css({"display":"block"});   
                            unlockModal()               
                }

最新更新