尝试使用 jQuery 绑定(bind)点击确认(以清理 JSF 页面中的代码) 我了解 MyFaces 编写的 onclick 内联函数 (oamSubmitForm();) 在 jQuery click() 事件之前执行。可以改为之前执行 jQuery 单击吗?
jQuery(".commandButtonConfirmDelete").click(function() {
var answer = confirm('Confirm Delete?');
return answer;
});
<h:commandLink styleClass="commandButtonConfirmDelete" />
<h:commandButton styleClass="commandButtonConfirmDelete" />
最佳答案
您最好的办法是检索内联点击事件,保存它,删除它,然后用您自己的函数覆盖它,该函数可以执行您想要执行的操作,并最终调用您删除的已保存函数。我会做这样的事情...
$(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();
});
});
看到这个 fiddle - http://jsfiddle.net/C9HTp/1/
alert('bar')
内联设置,alert('foo')
通过 .click()
绑定(bind)。然而,使用上述方法,警报按“foo”然后“bar”的顺序排列。
希望这有帮助!
关于jquery - 如何在 JSF <h :commandLink> or <h:commandButton> action is performed? 之前执行 jQuery click() 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5819777/