jquery動的にattr onclickを設定すること

1082 ワード

htmlコード:

<s:if test="#romAdResult.whether_release>0">
  <a href="#" onclick="activateCountUpdate(this,2)" id="${id}">    </a>
</s:if>
<s:else>
  <a href="#" onclick="activateCountUpdate(this,1)" id="${id}">  </a>
</s:else>

ビジネス要件:
1、ページロード時にwhether_によるreleaseの値は、0の場合はパブリケーションが表示され、0より大きい場合は1の場合はパブリケーションのキャンセルが表示されます.
2、JSコード操作では、「リリース解除」をクリックして実行に成功した後、改变了运动员的活动,有必要改变电视员,操作运动员的活动,正反对,Jquery需要改变onclick.質問:1、直接設定:$(this).attr("click",activateCountUpdate($(this),2)); 如果这样设定的话,直接实行活动会发生.2,在Jquery one设定: $(this).one("click",function(){ activateCountUpdate($(this),2) }); 设定后,如果把活动托里加弄掉的话,可以同时进行activateCountUpdate($(this),1)和activateCountUpdate($(this),2)的活动.最終的な解決方法: //クリアしてからバインド $(this).attr('onclick',''); //この方法が機能しない場合は、「$(this).unbind('click');」を使用します。に代わる $(this).one("click",function(){ activateCountUpdate($(this),2) });