我想引用页面上所有的 anchor 标签
<body>
<h1>not me</h1>
<a href ="google.com"></a>
<h1>not me also </h1>
<a href ="fb.com"></a>
<h2>me also as i am H2 </h2>
<a href ="FIDDLE.com"></a>
<h3>not me also </h3>
<a href ="fbO.com"></a>
<h2>me also as i am H2 </h2>
<a href ="FIDDLE2.com"></a>
<button onclick="score2Dmatrix();" id="btn" ></button>
h2 标签作为他们使用 jquery 的父标签,为此我必须通过每个具有父 h2 的 anchor 标签,然后添加属性
onclick="callme();";
我正在使用该代码 onclick
<script>
function callme() {
$("h2 a").each(function () {
$(this).attr("onclick", "score2Dmatrix();");
});
};
</script>
但没有努力 fiddle 的链接是这个jsfiddle
感谢托比的回答是正确的
selector(h2 + a)...
最佳答案
请参阅:https://jsbin.com/towejoqudu/edit?html,js,console,output
我已将文本添加到您的 anchor 中,以便您实际点击它们。
关于javascript - 使用 jquery 遍历 html 页面的所有 anchor 标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36193900/