找出在onClickTopics中点击了哪个链接

时间:2012-02-07 03:55:50

标签: jquery struts2

<script type="text/javascript">
      $.subscribe('linkclicked',function(){
          //code to find out the id of which sj:a was clicked
      }); </script>

<sj:a id="link1" href="n1.action" targets="maindiv" onClickTopics="linkclicked">Link1</sj:a>
<sj:a id="link2" href="n2.action" targets="maindiv" onClickTopics="linkclicked">Link2</sj:a>
<sj:a id="link2" href="n3.action" targets="maindiv" onClickTopics="linkclicked">Link3</sj:a>

应该编写哪些代码来查找被点击的链接的ID?

1 个答案:

答案 0 :(得分:-1)

您可以使用处理程序中第一个参数的event对象来查找触发事件的目标元素。试试这个。

$.subscribe('linkclicked',function(event){
      //code to find out the id of which sj:a was clicked
      alert(event.target.id);
});