问题描述
我正在尝试使用它:
$('#delete').live('click',function(){
var result;
bootbox.confirm("Are you sure?", function(response){
result=response;
});
alert(result);
return result;
});
但点击按钮后:
警报首先显示,然后才显示启动框显示确认对话框。
Alert is shown first and only after that bootbox shows confirm dialog.
我想返回响应,但是如果我在回调中执行此操作则不起作用因为它返回来自回调的响应但不返回$('#devicedelete')。live('click',function(){});
I want to return the response , but if i do it from within call back it doesn't work because it returns response from callback but not $('#devicedelete').live('click',function(){});
顺便说一下我正试图根据回复提交表格。因此,如果我返回'true'表单将被提交,否则如果它返回'false',表单将不会被提交。
Btw i'm trying to submit a form basing on response. So if i return 'true' form will be submitted, else if it returns 'false', form wont be submitted.
请检查:
我有一个包含每行复选框的大表,用户选中复选框并单击任何按钮'删除','复制'等,并提交表格。
I have one big table with checkboxes for each row, users select checkboxes and click on any of the buttons 'delete' , 'copy' etc and form should be submitted.
谢谢
推荐答案
对话框是异步的,您可以立即阻止默认操作,然后在用户接受时调用提交。以下是一个示例:
The dialog is async, you can prevent the default action right away, and then call the submit if the user accepts. Here is an example: http://jsfiddle.net/ty5Wc/3/
$('#delete').on('click', function (e) {
e.preventDefault();
bootbox.confirm("Are you sure?", function (response) {
if(response) {
$('#form').submit();
}
});
});
$('#form').submit(function () {
//do your validation or whatever you need to do before submit
});
编辑:在与OP交谈之后,他还想在查询字符串中传递按钮值,我的解决方法是:
After talking more with OP, he also wanted to pass button value in the query string, my solution for that is here: http://jsfiddle.net/ty5Wc/5/
$('#delete').on('click', function (e, confirmed) {
if (!confirmed) {
e.preventDefault();
bootbox.confirm("Are you sure?", function (response) {
if (response) {
$('#delete').trigger('click', true);
}
});
}
});
$('#form').submit(function (e) {
//do your validation or whatever you need to do before submit
});
这篇关于Bootbox回调无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!