twitter-bootstrap 推特引导模式对话框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13145534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
twitter bootstrap modal dialog
提问by Mihai Totoianu
I have a problem with a Twitter Bootstrap modal dialog.
HTML code:
我的 Twitter Bootstrap 模式对话框有问题。
HTML代码:
<div class="container">
<div class="delete_dosar">delete</div>
</div>
<!-- Boostrap modal dialog -->
<div id="delete_confirmation" class="modal hide fade" style="display: none; ">
<div class="modal-header">
<a href="#" class="close" data-dismiss="modal">x</a>
<h3>Are you sure?</h3>
</div>
<div class="modal-body">
<div class="paddingT15 paddingB15" id="modal_text">
Are you sure with this?
</div>
</div>
<div class="modal-footer">
<a href="#" class="btn confirm_delete_the_item no_return">yes</a>
<a href="#" class="btn btn-secondary " data-dismiss="modal">no</a>
</div>
</div>?
The JS code:
JS代码:
$(function() {
$(".delete_dosar").live('click',function(){
$('#delete_confirmation').modal("show");
$('.confirm_delete_the_item').live('click',function(e){
$('#delete_confirmation').modal("hide");
//e.preventDefault();
alert('x');
});
return false;
});
});?
the code is running here: http://jsfiddle.net/darkwish02/u7hEv/
代码在这里运行:http: //jsfiddle.net/darkwish02/u7hEv/
If i click "delete" and "yes", the first time I have only one alert, but if I click "delete" for a second time (without refreshing) I will have 2 alerts.
如果我单击“删除”和“是”,第一次我只有一个警报,但如果我第二次单击“删除”(不刷新),我将有 2 个警报。
The event "click" seems to run 2 consecutive times.
事件“click”似乎连续运行了 2 次。
回答by fegemo
The way you're doing, it's attaching a new click handler each time the delete button is clicked.
您的做法是,每次单击删除按钮时,它都会附加一个新的单击处理程序。
You should move the inner click handler insertion out of the first one. Then, there will always be just one handler for the "yes" button.
您应该将内部单击处理程序插入移出第一个。然后,“是”按钮将始终只有一个处理程序。
This fiddle shows it working: http://jsfiddle.net/KSxJs/
这个小提琴显示它工作:http: //jsfiddle.net/KSxJs/
$(function() {
$('.confirm_delete_the_item').live('click', function(e) {
$('#delete_confirmation').modal("hide");
//e.preventDefault();
alert('x');
});
/** SETERGERE DE DOSAR DIN PARTEA STANGA **/
$(".delete_dosar").live('click', function() {
$('#delete_confirmation').modal("show");
return false;
});
});?
回答by nakupanda
I would suggest you to use bootbox or bootstrap-dialog to do so.
我建议您使用 bootbox 或 bootstrap-dialog 来执行此操作。
See:
看:

