0

以下の jQuery UI ダイアログフォームで、「OK」または「キャンセル」がクリックされたかどうかを「閉じる」コールバック関数内で追跡するにはどうすればよいですか?

$( "#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 に答える