jquery - 如何在 JSF <h :commandLink> or <h:commandButton> action is performed? 之前执行 jQuery click() 事件

标签 jquery jsf myfaces

尝试使用 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/

相关文章:

javascript - 使用 AjaxFileUpload 函数

jquery - 通过鼠标悬停和 animate.css 对元素进行动画处理

javascript - 根据输入表单中输入的内容分别弹出不同的表单

jquery - 通过 JQuery 在 JSF inputText 控件上写入数据

jsf - EE4J、JSF 规范、MyFaces 和 future 方向

jsf - 使用请求参数打开详细 View

JSF 2.2 : Configure available Locales outside faces-config. xml

jquery - 更改输入元素的类型

jsf - 动态 Primefaces :tabView doesn't update

java - "Unknow type constant pool at position X"在自 java 8 以来的 tomcat 日志中