jQuery button debugging - determine what is causing navigation/postback event
I have a jQuery UI button that is being used inside of a jqGrid column. This button is disabled until the onSelectRow
event is triggered and the corresponding button for the row is enabled.
This button when generated looks something like this (psudocode).
<button id=\"" + ids[i] + "_SaveButton\" class=\"SaveButton\" onclick=\"return false;\">Save</button>
$(".SaveButton").button({ icons: { primary: 'ui-icon-check' }, text: false, disabled: true }).css({ width: "45px" });
onSelectRow: function () {
$("#" + _LastSel + "_SaveButton").开发者_如何转开发button("disable");
$("#" + ID + "_SaveButton").button("enable");
}
This button must return false to prevent a postback of the page occurring.
My problem lies in that somewhere in all my code when the onSelectRow
event is triggering I am getting a postback occurring.
Interestingly this only occurs when the onSelectRow
is triggered from the column that contains the save button but I digress.
Basically what I am hoping is someone can give me an idea of how I might determine what event and from which DOM element is triggering the postback. I have attempted to use the jQuery.unload()
event but this does not provide information regarding what triggered it (at least from what I can see looking thru the eventData object).
Anyone have any ideas?
Probably one of the events is bubbling up to the form, causing submit. Probably from the way you're binding onSelectRow--try adding an event.preventDefault() in there.
Also hooking the form submit event, then examining event.originalEvent and event.originalTarget.
Also, I recommend against mixing onclick attributes with modern jQuery behavior binding.
精彩评论