如何在 JSF之前执行 jQuery click() 事件?或执行操作?
尝试使用 jQuery 绑定点击确认(以清理 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" />
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" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您最好的选择是检索内联点击事件,保存它,删除它,然后用您自己的函数覆盖它,该函数可以执行您想要执行的操作,并最终调用您删除的已保存函数。我会做这样的事情...
请参阅这个小提琴 - http://jsfiddle.net/C9HTp/1/
alert('bar')
设置为内联,alert('foo')
通过.click()
绑定。然而,使用上述方法,警报按“foo”然后“bar”的顺序排列。希望这有帮助!
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...
See this fiddle - http://jsfiddle.net/C9HTp/1/
alert('bar')
is set inline andalert('foo')
is bound via.click()
. However using the method described above, the alerts go in order of 'foo' then 'bar'.Hope this helps!
如果您可以使用 ID,则可以将 client-ids 用于点击事件。
jQuery("#formId:commandButtonConfirmDelete").click(function() {
varanswer=confirm('确认删除?');
返回答案;
});
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" />