【发布时间】: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