【问题标题】:jQuery UI Dialog - Won't open the first timejQuery UI 对话框 - 第一次不会打开
【发布时间】:2011-08-31 23:35:57
【问题描述】:

我使用 jQuery UI 对话框作为确认框,当您单击链接时,对话框将打开,其中包含问题和两个按钮。 但是我在对话框中遇到了一些负载问题。当我第一次访问该页面时,对话框不会打开。当我按 F5 并再次尝试时,它工作正常。

这是我的代码:

<script type="text/javascript">
$(document).ready(function() {
var url;

$( "#dialog" ).dialog( {
    autoOpen: false,
    resizable: false,
    modal: true,
    buttons: {
        "Yes": function() {
            $(this).dialog("close");
            window.location.href = url;
        },
        "No": function() {
            $(this).dialog("close");
        }
    }
});

$("a.supportClub").click(function(e) {
    e.preventDefault();
    url = e.target;
    $("#dialog").dialog("open");
});  
});
</script>


<div id="dialog" title="Support club" style="display: none">
    <p>The question</p>
</div>   

<a href="?supportClub=5" class="button right supportClub">Support</a>

希望有人能帮助我。

谢谢!

【问题讨论】:

    标签: jquery jquery-ui caching dialog


    【解决方案1】:
    $("a.supportClub").click(function(e) {
        e.preventDefault();
        url = e.target;
        $('#dialog').dialog('destroy');
        $("#dialog").dialog();
    }); 
    

    【讨论】:

      【解决方案2】:

      试试这个:

      <script type="text/javascript">
      $(document).ready(function() {
      function showDialog(url){
           $( "#dialog" ).dialog( {
              resizable: false,
              modal: true,
              buttons: {
                  "Yes": function() {
                      $(this).dialog("close");
                      window.location.href = url;
                  },
                  "No": function() {
                      $(this).dialog("destroy");
                  }
              }
          });
        }
      
      $("a.supportClub").click(function(e) {
          e.preventDefault();
          showDialog(e.target);
        });  
      });
      </script>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-04-29
        • 1970-01-01
        • 2010-12-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-16
        • 1970-01-01
        相关资源
        最近更新 更多