简体   繁体   English

每个用户一次显示jquery对话框

[英]Show jquery dialog once per user

I use modal dialog on page open and I'd like to show it once for each user. 我在打开页面时使用模式对话框,我想为每个用户显示一次。 Here is the code,but it doesn't work 这是代码,但是不起作用

<script type="text/javascript">
// <![CDATA[
$(document).ready(function(){
    $("#dialog").dialog({
        modal: true
    }); 
    $(function() {
        if ($.cookie('shownDialog') != 'true') {
            $('#dialog').dialog();
        }
        $.cookie('shownDialog', 'true', {expires: 7});
    });
    $("#close").click(function(event) {
        event.preventDefault();
        $(this).closest(":ui-dialog").dialog("close");
    });
});
// ]]>
</script>

Can someone help me to fix code? 有人可以帮我修复代码吗?

I'm guessing you're seeing the dialog always instead of once per user. 我猜想您总是看到对话框,而不是每个用户一次。

$(document).ready(function(){
     $("#dialog").dialog({
                modal: true
}); 

This part is going to show the dialog immediately, before ever reaching your check for display. 这部分将立即显示对话框,直到您检查要显示。

You should get rid of it and move your modal option into the if block instead: 您应该摆脱它,并将模式选项移到if块中:

<script type="text/javascript">
// <![CDATA[
$(document).ready(function(){
    $(function() {
          if ($.cookie('shownDialog') != 'true') {
              $("#dialog").dialog({
                    modal: true
               }); 
          }
          $.cookie('shownDialog', 'true', {expires: 7});
    });
    $("#close").click(function(event) {
      event.preventDefault();
      $(this).closest(":ui-dialog").dialog("close");
    });
});
// ]]>
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM