[英]JQuery: binding click event to multiple href's not working properly
I am binding the click event to 4 href's (they have class="alink") using JQuery in the ready() event like this: $(".alink").click(function() { debugger; }); 我在ready()事件中使用JQuery将click事件绑定到4 href(它们具有class =“ alink”),例如:$(“。alink”)。click(function(){debugger;});
I expect whenever I click on a link, the event fires. 我希望每当我单击链接时都会触发该事件。 However what I notice is that sometimes it doesn't fire and when it fires, it fires 4 times.
但是,我注意到的是,有时它不会触发,并且在触发时会触发4次。 Am I not doing it right?
我做错了吗?
EDIT: 编辑:
<div id="nav">
<ul>
<li class="current"><a href="default.aspx" title="Home" class="alink">home</a></li>
<li><a href="faq.aspx" class="alink">faq</a></li>
<li><a href="" title="Webmail" class="alink">webmail</a></li>
<li><a href="contactus.aspx" title="contact" class="alink">contact us</a></li>
</ul>
</div>
Actually I found the problem. 其实我发现了问题。 The event handler was inside another function!
事件处理程序在另一个函数中!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.