2

jQuery でクリック確認をバインドしようとしている (JSF ページ内のコードをきれいにするため) jQuery の click() イベントの前に、MyFaces によって記述された onclick インライン関数 (oamSubmitForm();) が実行されることがわかりました。代わりに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 を使用できる場合は、クリック イベントにクライアント ID を使用できます。

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

于 2011-04-28T14:12:18.350 に答える