2

尝试将单击确认与 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" />  
4

2 回答 2

2

你最好的办法是检索内联点击事件,保存它,删除它并用你自己的函数覆盖它,做你想做的事情,最终调用你删除的保存函数。我会做这样的事情......

$(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();
  });
});

看到这个小提琴 - http://jsfiddle.net/C9HTp/1/

alert('bar')设置为内联并alert('foo')通过.click(). 然而,使用上述方法,警报按“foo”然后“bar”的顺序进行。

希望这可以帮助!

于 2011-04-28T14:06:28.017 回答
0

如果您可以使用 ID,则可以将 client-ids 用于单击事件。

jQuery("#formId:commandButtonConfirmDelete").click(function() { var answer = confirm('Confirm Delete?'); return answer; });
<h:commandButton id="commandButtonConfirmDelete" />

于 2011-04-28T14:12:18.350 回答