开发者

jquery ui dialog - how to determine which input opened the dialog?

开发者 https://www.devze.com 2023-02-19 18:59 出处:网络
I want to find out which input opened the dialog. $(\'#dialog\').dialog({ autoOpen: false, open: function (event, ui) {

I want to find out which input opened the dialog.

        $('#dialog').dialog({
            autoOpen: false,
            open: function (event, ui) {
                // find the opening button here?
            },
            buttons: {
                "Save": function () {

                    // if button "Add" opened dialog
                    // do something...

                    // if button "Edit" opened dialog
                    // do something...
                },
         开发者_开发问答       Cancel: function () {
                    $(this).dialog("close");
                }
            }
        });

<form id="myForm">
<input id="Add" type="button" value="Add" />
<input id="Edit" type="button" value="Edit" />
</form>


During debugging, set a breakpoint on the modal dialog code. When it is reached, the stack trace should show you what input triggered it. If during production use, instrument your code that calls the modal dialog to store a string representing the calling context in some convenient persistent place (as a new 'window' property, for example). Then the modal dialog can fetch the calling context. I doubt that jquery itself can do this.

0

精彩评论

暂无评论...
验证码 换一张
取 消