8

I'm trying to use this:

 $('#delete').live('click',function(){
                var result;
                bootbox.confirm("Are you sure?", function(response){
                        result=response;
                });
                alert(result);
                return result;
            });

But when the button is clicked:

Alert is shown first and only after that bootbox shows confirm dialog.

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(){});

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.

Please check this: http://pastebin.com/9H3mxE9Y

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.

Thanks

4

1 回答 1

4

该对话框是异步的,您可以立即阻止默认操作,然后在用户接受时调用提交。这是一个例子: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 进行了更多交谈后,他还想在查询字符串中传递按钮值,我的解决方案在这里: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
});
于 2013-05-26T13:33:44.660 回答