jQuery选择器,用于带有href属性中的#的链接 [英] jQuery selector for links with # in href attribute
本文介绍了jQuery选择器,用于带有href属性中的#的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用此jQuery选择器:
I tried to use this jQuery selector:
$("a:has(href*=#)").click(function() {
alert('works');
});
但是它似乎不起作用.我想选择所有在href属性中具有锚点的标签(在其中带有#符号)
but it doesn't seem to work. I would like to select all tags which have anchor in href attribute (has # symbol there)
推荐答案
$("a[href*=#]").click(function(e) {
e.preventDefault();
alert('works');
});
这篇关于jQuery选择器,用于带有href属性中的#的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文