Javascript 按顺序显示引导模式对话框

Javascript 按顺序显示引导模式对话框,javascript,jquery,twitter-bootstrap,Javascript,Jquery,Twitter Bootstrap,我有一个引导模式对话框,当选择“是”时,它返回一个已解决的承诺。解决承诺后,应再次显示模式。点击显示模式的行,但不显示模式。我做错了什么 $(函数(){ showModalDialog('Confirm1','Select Yes or No','Yes','No') .done(函数(){ 警报(“您选择了一次是!”); showModalDialog('Confirm2','Select Yes or No','Yes','No') .done(函数(){ 警报('您选择了两次是!');

我有一个引导模式对话框,当选择“是”时,它返回一个已解决的承诺。解决承诺后,应再次显示模式。点击显示模式的行,但不显示模式。我做错了什么

$(函数(){
showModalDialog('Confirm1','Select Yes or No','Yes','No')
.done(函数(){
警报(“您选择了一次是!”);
showModalDialog('Confirm2','Select Yes or No','Yes','No')
.done(函数(){
警报('您选择了两次是!');
});
});
});
函数showModalDialog(标题、消息、按钮1标题、按钮2标题){
var deferred=$.deferred();
$('#modaltile').html(标题);
$('#modalMessage').html(消息);
$('#modalButton1').html(button1标题);
$('#modalButton2').html(button2标题);
$('modalButton1')。一('click',function(){
延迟。解决();
});
$('modalButton2')。一('click',function(){
拒绝();
});
$('#modalDialog').one('hidden.bs.modal',function(){
//如果按钮从未被调用,请删除该按钮的处理程序,否则它将被调用
//下一次显示对话框时仍在那里
$('modalButton1')。关闭('click');
拒绝();
})
$('modalDialog').modal();
延迟返回。承诺();
}

归咎于动画!:)

隐藏模式的动画需要一些有限的时间才能完成。如果在此期间再次尝试“显示”模态,则它将不起作用。一个简单的解决方法是稍微延迟“show”操作

例如,延迟一秒钟就可以了:

setTimeout(function() {
    showModalDialog('Confirm2', "Select Yes or No", 'Yes', 'No')
      .done(function() {
        alert('You selected Yes twice!');
      });
}, 1000);
$(函数(){
showModalDialog('Confirm1','Select Yes or No','Yes','No')
.done(函数(){
警报(“您选择了一次是!”);
setTimeout(函数(){
showModalDialog('Confirm2','Select Yes or No','Yes','No')
.done(函数(){
警报('您选择了两次是!');
});
}, 1000);
});
});
函数showModalDialog(标题、消息、按钮1标题、按钮2标题){
var deferred=$.deferred();
$('#modaltile').html(标题);
$('#modalMessage').html(消息);
$('#modalButton1').html(button1标题);
$('#modalButton2').html(button2标题);
$('modalButton1')。一('click',function(){
延迟。解决();
});
$('modalButton2')。一('click',function(){
拒绝();
});
$('#modalDialog').one('hidden.bs.modal',function(){
//如果按钮从未被调用,请删除该按钮的处理程序,否则它将被调用
//下一次显示对话框时仍在那里
$('modalButton1')。关闭('click');
拒绝();
})
$('modalDialog').modal();
延迟返回。承诺();
}

归咎于动画!:)

隐藏模式的动画需要一些有限的时间才能完成。如果在此期间再次尝试“显示”模态,则它将不起作用。一个简单的解决方法是稍微延迟“show”操作

例如,延迟一秒钟就可以了:

setTimeout(function() {
    showModalDialog('Confirm2', "Select Yes or No", 'Yes', 'No')
      .done(function() {
        alert('You selected Yes twice!');
      });
}, 1000);
$(函数(){
showModalDialog('Confirm1','Select Yes or No','Yes','No')
.done(函数(){
警报(“您选择了一次是!”);
setTimeout(函数(){
showModalDialog('Confirm2','Select Yes or No','Yes','No')
.done(函数(){
警报('您选择了两次是!');
});
}, 1000);
});
});
函数showModalDialog(标题、消息、按钮1标题、按钮2标题){
var deferred=$.deferred();
$('#modaltile').html(标题);
$('#modalMessage').html(消息);
$('#modalButton1').html(button1标题);
$('#modalButton2').html(button2标题);
$('modalButton1')。一('click',function(){
延迟。解决();
});
$('modalButton2')。一('click',function(){
拒绝();
});
$('#modalDialog').one('hidden.bs.modal',function(){
//如果按钮从未被调用,请删除该按钮的处理程序,否则它将被调用
//下一次显示对话框时仍在那里
$('modalButton1')。关闭('click');
拒绝();
})
$('modalDialog').modal();
延迟返回。承诺();
}


在中,他们说for
hidden.bs.modal
:当对用户隐藏模式完成时(将等待CSS转换完成),会触发此事件。我猜移动
deferred.resolve()
to
hidden.bs.modal
事件也可以解决这个问题,而不需要猜测需要多长时间add@ljubadr是的,那将是一个更好的方法。更新了帖子。顺便说一句,你似乎在做一些非常类似的事情。你应该去看看。我想他们用回电而不是承诺。太棒了,谢谢你们。我以前没有见过Bootbox,我会查看它。在中,他们说for
hidden.bs.modal
:当对用户隐藏模式完成时(将等待CSS转换完成),会触发此事件。我猜移动
deferred.resolve()
to
hidden.bs.modal
事件也可以解决这个问题,而不需要猜测需要多长时间add@ljubadr是的,那将是一个更好的方法。更新了帖子。顺便说一句,你似乎在做一些非常类似的事情。你应该去看看。我想他们用回电而不是承诺。太棒了,谢谢你们。我以前没见过Bootbox,我来看看。