0

在下面的 jQuery UI 对话框表单中,如何在“关闭”回调函数中跟踪是否单击了“确定”或“取消”?

$( "#dialog-form" ).dialog( "option", "buttons", 
    [ 
        { 
            text: "OK", 
            click: function() { 
                // sone action...
                $( this ).dialog( "close" );
            }
        },
        {
            text: "Cancel", 
            click: function() { 
                $( this ).dialog( "close" );
            }
        }
    ] 
);

$( "#dialog-form" ).dialog({
    close: function(event, ui) {
        // Track here whether 'OK' or 'Cancel' was clicked...
    }
});
4

1 回答 1

0

除非有内置的方法可以做到这一点,否则您可以执行以下操作:

$( "#dialog-form" ).dialog( "option", "buttons", 
    [ 
        { 
            text: "OK", 
            click: function() { 
                // sone action...
                $("#dialog-form").data({ lastClick: 'ok' });
                $( this ).dialog( "close" );
            }
        },
        {
            text: "Cancel", 
            click: function() { 
                $("#dialog-form").data({ lastClick: 'close' });
                $( this ).dialog( "close" );
            }
        }
    ] 
);

$( "#dialog-form" ).dialog({
    close: function(event, ui) {
        // Track here whether 'OK' or 'Cancel' was clicked...
        var lastClick = $("#dialog-form").data('lastClick');
        if(lastClick)
            console.log(lastClick);
    }
});
于 2013-09-09T13:55:20.130 回答