如何编写jQuery选择器以查找带有#in href属性的链接?
示例
您可以尝试运行以下代码来编写jQuery选择器,以在href中查找带有#的链接。在这里,^用于查找href中以#开头的链接。
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('a[href^="#"]').click(function(){
alert('Success! Selected link starting with # in href.');
});
});
</script>
</head>
<body>
<a href="#demo" title="new" >Demo</a><br>
<a href="/cplusplus/" title="C++ Tutorial" >C++</a>
</body>
</html>热门推荐
2 孙媳妇祝福语简短
10 祝福语简短七夕
11 小寒健康祝福语大全简短
12 英文写结婚祝福语简短
13 宝宝新年祝福语大全简短
14 简短中秋祝福语朋友结婚
15 给儿子生日祝福语 简短
16 祝福语对联文案简短大气
17 古风中考祝福语简短
18 新婚祝福语简短句子