0

您好,我正在使用结合 cookie 的 Reveal 弹出式插件来每天仅显示一次弹出式窗口。这是我的代码

<head>
..
<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;
        }

        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;
        }

        function showModal() {
            // Check if cookie existes
            var expireDate = getCookie("showpopup");
            var today = new Date().toUTCString();

            if (expireDate != null && expireDate > today) {
                //Do nothing!
            }
            else {
                //ShowPopup here!
                $('a.reveal-link').trigger('click');

                //Create cookie
                setCookie("showpopup", "anything", 1);
            }
        }        
    </script>
</head>

<body onLoad="showModal()">
<a href="#" data-reveal-id="myModal" class="reveal-link">Click Me For A Modal</a>
<div id="myModal" class="reveal-modal">
     <h1>Modal Title</h1>
     <p>Any content could go in here.</p>
     <a class="close-reveal-modal">&#215;</a>
</div>
...other code
</body>

所以基本上在页面加载时,cookie 被创建但没有弹出显示。当我手动单击链接“Click Me For A Modal”时,会显示窗口,因此窗口没有问题。当我尝试有效的javascript警报消息时。代码的重要部分是:

 //ShowPopup here!
                $('a.reveal-link').trigger('click');

我尝试了不同的变体来启动脚本$('#myModal').foundation('reveal', 'open');$('#myModal').reveal();但没有任何效果。你能帮助我吗 ?谢谢

4

1 回答 1

0

我找到了。由于更多的 jquery 库发生冲突,问题只是出现在我的页面上。

于 2013-09-12T14:32:24.007 回答