【问题标题】:How do I bind a close button with an open button using jQuery UI Dialog?如何使用 jQuery UI 对话框将关闭按钮与打开按钮绑定?
【发布时间】:2013-01-19 19:08:30
【问题描述】:

我正在尝试使用 5 个 jQuery 对话框模式创建类似向导的体验。我想从第一个打开第二个但关闭第一个的新模态。第三、第四、第五个也一样。

我可以很好地打开嵌套在其他模态中的模态,但是当下一个打开时,前一个不会关闭。最后,我打开了 5 个窗口。

这是我用来打开 5 个模态中的两个的代码(其余的将使用相同的逻辑按顺序排列:

<script>
  $(function() {
   $( "#modal_1" ).dialog({position:['middle',60],
        open: function(event, ui) {  
        dialogClass: 'ui-widget-shadow',
        modal: true,    
        autoOpen: false,
        width: '950px',
        close: function(ev, ui) {$(this).close();}
        });

    $( ".modal_1open" ).click(function() {
      $( "#modal_1" ).dialog( "open" );
        return false;
        });

    $( ".btnNext" ).click(function(){
      $('.ui-dialog-content').dialog( "close" );
        })
    });
</script>
<script>
  $(function() {
   $( "#modal_2" ).dialog({position:['middle',60],
        open: function(event, ui) {  
        dialogClass: 'ui-widget-shadow',
        modal: true,    
        autoOpen: false,
        width: '950px',
        close: function(ev, ui) {$(this).close();}
        });

    $( ".modal_2open" ).click(function() {
      $( "#modal_2" ).dialog( "open" );
        return false;
        });

    $( ".btnNext" ).click(function(){
      $('.ui-dialog-content').dialog( "close" );
        })
    });
</script>

这是一个html示例:

<a class="button btnNext">Continue</a> <!--this is the button inside the modal that is supposed to fire the next modal-->

<div style="display:none" id="modal_1" title="Login">
  <!--#include file="modal_1.asp"-->
</div>
<div style="display:none;" id="modal_2" title="Page Two Title">
  <!--#include file="modal_2.asp"-->
</div>

我想我可以将 close 函数与 next 的打开绑定,但我不知道如何。有什么帮助吗??

【问题讨论】:

  • 这是一个糟糕的设计模式。为什么不只更新单个模态的内容?
  • 我看到了另一个类似的帖子,看起来是一样的,但我需要一些帮助才能让它与我的代码一起使用:stackoverflow.com/questions/5718261/…

标签: javascript jquery-ui dialog bind


【解决方案1】:

我对您的代码进行了节食以提供线索并进行了一些测试。 IMO 你错过了分配的选项。 close:用于事件处理程序,而不是按钮。 使用按钮字段定义按钮。当点击关闭你的对话框并打开下一个...

 $(this).dialog("close");
 $("#modal_2").dialog("open");

下面是我的简单版本:

$(function() {
$("#modal_1").dialog({
    modal: true,
    autoOpen: true,
    buttons: [{text: "Next",click: function() {
                $(this).dialog("close");
                $("#modal_2").dialog("open");
            }
        }]
});

$("#modal_2").dialog({
    modal: true,
    autoOpen: false,
    buttons: [{text: "Next",click: function() {
                $(this).dialog("close");
                $("#modal_1").dialog("open");
            }}]
});
});

我在这里测试过: http://jsfiddle.net/JmgKS/8/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 2014-08-02
    • 2010-10-31
    • 1970-01-01
    • 2016-04-13
    • 2010-10-28
    相关资源
    最近更新 更多