锚点上的jquery点击事件 [英] jquery click event on anchor
本文介绍了锚点上的jquery点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里是html的片段:
Here's the snippet of html i have:
<div id="tag-cloud-widget">
<div class="content">
<a href="#" rel="1" class="cloud-element" data-tag-id="10" style="font-size: 12px; color: rgb(205, 236, 222); ">T1</a>
<a href="#" rel="1" class="cloud-element" data-tag-id="1" style="font-size: 12px; color: rgb(205, 236, 222); ">T2</a>
<a href="#" rel="1" class="cloud-element" data-tag-id="3" style="font-size: 12px; color: rgb(205, 236, 222); ">T3</a>
</div>
</div>
我想设置一个点击处理程序来响应用户点击锚标签。这里是测试代码:
I'd like to set up a click handler to respond to the user's click on the anchor tags. Here's the test code:
$("#tag-cloud-widget .content a").click(function(e) {
alert('clicked');
return false;
});
上面的点击处理程序不会被触发,也不会:
The click handler above does not get fired and neither does this:
$("#tag-cloud-widget .content .cloud-element").click(function(e) {
alert('clicked');
return false;
});
但是,
$("#tag-cloud-widget .content").click(function(e) { ... });
和
$("#tag-cloud-widget").click(function(e) { ... });
我看不到什么?
推荐答案
锚点击事件,总是使用 e.preventDefault();
时,你不需要锚。
发挥像魅力
When handling anchor click events, always use e.preventDefault();
when you don't need the anchor anyway.
Fires like a charm
这篇关于锚点上的jquery点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文