我尝试让以下代码工作
//===== Dialogs =====//
$(".table a.delete").click(function (e) {
e.preventDefault();
bootbox.confirm("Are you sure?", function (confirmed) {
if (confirmed) {
var $el = $(this);
var $tr = $el.closest('tr');
var url = $el.closest('table').data('remove-url');
var id = $tr.data('id');
$tr.fadeOut(function () {
$el.remove();
$.post(url, { id: id }); // do the delete on the server
});
}
});
});
引导框已显示,但 if(confirmed)
下面的代码未运行。
最佳答案
匿名 bootbox 方法中的 $(this) 并不指代您认为它所做的事情。 if(已确认)内的代码被执行,但没有匹配到任何内容。
$(".table a.delete").click(function (e) {
var $el = $(this);
e.preventDefault();
bootbox.confirm("Are you sure?", function (confirmed) {
if (confirmed) {
var $tr = $el.closest('tr');
... etc
}
});
};
关于javascript - jQuery 引导框对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14333303/