日期:2014-05-16  浏览次数:20331 次

jquery给A标签注册click事件后无法触发
RT  使用jq each函数对页面a标签注册click事件

 场景:点击A标签,事件触发;点击button触发函数中使用$("#a标签id").click();却无法触发相应a标签事件
 
 问题:为啥以委托触发的形式无法触发事件呢?

 期待高手解释一下......
jQuery

------解决方案--------------------
楼主上代码吧,不然看不出哪里有问题
我自己写了个小测试,完全没问题。

------解决方案--------------------

<a id="a" href="http://www.baidu.com">baidu</a>
    <br />
    <button id="button">click</button>
    <script type="text/javascript">
        document.getElementById("a").onclick = function() {
            alert("触发A标签click事件");
        };
        document.getElementById("button").onclick = function() {
            document.getElementById("a").onclick();
        };
    </script>

通过以上代码可以看出a标签的click事件跟页面跳转没有关系
要实现跳转必须鼠标去点 以上代码在IE8和火狐中是这样的,其他浏览器不清楚
------解决方案--------------------

$.("a").each(function(){
$(this).on("click",function(){
alert(123);
});
});

------解决方案--------------------
初步估计事件绑定出错

$(document).ready(function(){
   $("a").click(){
      alert(this.id);
   }
}

试试