Trying to bind click confirmation with jQuery (to 开发者_开发问答clean code in JSF page) I understand that onclick inline function (oamSubmitForm();) written by MyFaces is executed before jQuery click() event. Is possible to do jQuery click before instead?
jQuery(".commandButtonConfirmDelete").click(function() {
var answer = confirm('Confirm Delete?');
return answer;
});
<h:commandLink styleClass="commandButtonConfirmDelete" />
<h:commandButton styleClass="commandButtonConfirmDelete" />
You're best bet is to retrieve the inline click event, save it, delete it and overwrite it with your own function that does what you want to do and eventually calls the saved function that you deleted. I'd do something like this...
$(function() {
var node = $('.commandButtonConfirmDelete').get(0),
savedAction = node.onclick;
//Remove the inline handler (we'll call it manually in our new handler)
node.onclick = null;
$(node).click(function() {
//do something
//then call your inline action
savedAction();
});
});
See this fiddle - http://jsfiddle.net/C9HTp/1/
alert('bar')
is set inline and alert('foo')
is bound via .click()
. However using the method described above, the alerts go in order of 'foo' then 'bar'.
Hope this helps!
If you can work with IDs, you can use client-ids for the click event.
jQuery("#formId:commandButtonConfirmDelete").click(function() {
var answer = confirm('Confirm Delete?');
return answer;
});
<h:commandButton id="commandButtonConfirmDelete" />
精彩评论