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.
精彩评论