不幸的是,文档 Bootbox(http://paynedigital.com/2011/11/bootbox-js-alert-confirm-dialogs-for-twitter-bootstrap)没有教如何调用确认对话框。因为它在页面加载时总是出现在文档窗口中,所以当通过单击删除按钮调用时应该出现错误。这是尝试失败的代码。
// show "false" does not work, the confirm window is showing when page is loaded.
$(function () {
bootbox.confirm("Confirm delete?", "No", "Yes", function(result) {
show: false
});
});
// need show the confirm window when the user click in a button, how to call the confirm window?
<td><a class="icon-trash" onclick="bootbox.confirm();" href="{% url 'del_setor' setor.id %}" title="Delete"></a></td>
如何设置此引导框仅在单击删除按钮时出现?谢谢!
编辑 - 解决方案:
$(function () {
$("a#confirm").click(function(e) {
e.preventDefault();
var location = $(this).attr('href');
bootbox.confirm("Confirm exclusion?", "No", "Yes", function(confirmed) {
if(confirmed) {
window.location.replace(location);
}
});
});
});
现在,当我单击“是”时,删除工作。我要求插件的开发人员将完整的示例放在文档中,这样用户就不需要创建关于如何在单击“是”时删除对象的帖子。问候。