Jquery 引导框确认对话框问题
不幸的是,docbootbox()没有教会如何调用confirm对话框。由于在加载页面时,文档窗口中总是显示错误,因此,单击删除按钮调用时,应该显示错误。 这是尝试失败的代码Jquery 引导框确认对话框问题,jquery,twitter-bootstrap,bootbox,Jquery,Twitter Bootstrap,Bootbox,不幸的是,docbootbox()没有教会如何调用confirm对话框。由于在加载页面时,文档窗口中总是显示错误,因此,单击删除按钮调用时,应该显示错误。 这是尝试失败的代码 // 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" 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>
现在,当我点击“是”时,删除工作正常。
我要求插件的开发人员将完整的示例放在文档中,这样用户就不需要在单击“是”时创建关于如何删除对象的帖子。
注意。您可能需要在本页“基本用法”下的“确认”链接上检查来源: 下面是一个片段:
$("a.confirm").click(function(e) {
e.preventDefault();
bootbox.confirm("Are you sure?", function(confirmed) {
console.log("Confirmed: "+confirmed);
});
});
假设jQuery在您正在使用的UI中可用,我会避免在锚定标记中使用
onClick
属性。只有我的两分钱。我也需要它,但我改变了一些事情。。。看看
$(document).on("click", ".confirm-modal", function(e) {
e.preventDefault();
bootbox.confirm("Are You sure?", function(result) {
if(result) {
top.location.href = e.target.href;
}
});
});
将此函数添加到全局“jQuery Ready”函数中,如下所示:
$(document).on("click", "[data-toggle=\"confirm\"]", function (e) {
e.preventDefault();
var lHref = $(this).attr('href');
var lText = this.attributes.getNamedItem("data-title") ? this.attributes.getNamedItem("data-title").value : "Are you sure?"; // If data-title is not set use default text
bootbox.confirm(lText, function (confirmed) {
if (confirmed) {
//window.location.replace(lHref); // similar behavior as an HTTP redirect (DOESN'T increment browser history)
window.location.href = lHref; // similar behavior as clicking on a link (Increments browser history)
}
});
});
<a class="btn btn-xs btn-default" data-toggle="confirm" data-title="Do you really want to delete the record 123?" href="/Controller/Delete/123"><span class="fa fa-remove"></span> </a>
只需在按钮或链接中添加一些“数据-*属性”,如下所示:
$(document).on("click", "[data-toggle=\"confirm\"]", function (e) {
e.preventDefault();
var lHref = $(this).attr('href');
var lText = this.attributes.getNamedItem("data-title") ? this.attributes.getNamedItem("data-title").value : "Are you sure?"; // If data-title is not set use default text
bootbox.confirm(lText, function (confirmed) {
if (confirmed) {
//window.location.replace(lHref); // similar behavior as an HTTP redirect (DOESN'T increment browser history)
window.location.href = lHref; // similar behavior as clicking on a link (Increments browser history)
}
});
});
<a class="btn btn-xs btn-default" data-toggle="confirm" data-title="Do you really want to delete the record 123?" href="/Controller/Delete/123"><span class="fa fa-remove"></span> </a>
所以。。。这样你就可以有一个个性化的问题。。这对您的用户来说更加直观
你喜欢吗
请参见演示:Aspx侧的网格链接按钮:
好的,谢谢你的回答!现在窗口出现了,但是当我点击“是”时,什么都没有发生,排除也没有发生。您好。您可能需要检查JS控制台,看看是否抛出了错误。如果看不到您正在处理的代码,就很难说是什么导致了问题。你能把它放到一个JSFIDLE中吗?代码已经发布了,没有必要在JSFIDLE中发布,因为我只有这段代码要显示。在那里我没有一个物体可以移除。发生的事情很简单,我单击“是”,对象不会被删除,尽管在firebug中显示为“已删除:真”。firebug中不会出现错误消息,只是不会删除对象。问候。对于这么晚的回答,你应该加上解释。笑-是的,这似乎是开发人员需要知道的事情。
function DeleteConfirm(btn, msg)
{
if(msg==''){msg='Are You Sure ? ';}
if ($(btn).attr('confirmOK')=='1'){return true;}
bootbox.confirm({
title: 'Confirm Popup',
message: msg,
callback: function(result) {
if (result)
{
$(btn).attr('confirmOK', '1');
btn.click();
}
else{
$(btn).attr('confirmOK', '0');
}
}
});
return false;
};