0

如果按下关闭(X),Boxy 不会等待确认。以下是描述我的问题的示例:

$('form .close').click(function(event) {
    event.stopPropagation();
    Boxy.confirm("Are you sure ?", function() {
        alert('ok');
    });
    return false;
});

但是,当OK单击按钮时,一切都按预期工作。

如果按下 ,为什么这不能按预期工作(X)

4

2 回答 2

1

请看我为你制作的这个例子:http: //jsfiddle.net/972ak/

$('form .close').click(function(event) {

            Boxy.confirm("Are you sure ?", function() {
                alert('ok');
            });
            return false;

    });

四四方方的文档说:

Boxy.confirm(message, callback, options) 显示一个模态的、不可关闭的对话框,显示带有确定和取消按钮的消息。只有当用户选择 OK 时才会触发回调。

http://onehackoranother.com/projects/jquery/boxy/

于 2014-05-26T11:01:11.017 回答
0

As I have already mentioned in my comment Boxy.confirm is async unlike native confirm. Your code will continue its execution without waiting for user to click OK or Cancel. That is why you need to perform the actual action inside confirm callback.

Consider the following code.

$('form .close').click(function(e){
    var form = $(this).closest('form');

    Boxy.confirm('Are you sure?', function() {
        form.remove(); //remove it only if user confirmed.    
    });

    form.append('<p>Close was clicked.</p>');

})

This code will append message every time user clicks close link. But the form will be actually removed only if user confirmed the action.

http://jsfiddle.net/tarabyte/972ak/4/

于 2014-05-26T11:31:56.067 回答