这是我的 HTML 代码
var link = document.getElementsByClassName("link");
for (i = 0; i < link.length; i++) {
link[i].addEventListener("click", click);
function click() {
console.log(link.indexOf(this));
}
}
<div class="links">
<ul>
<li>
<div class="hole-counter"><span></span></div><a class="link">Home</a>
</li>
<li>
<div class="hole-counter"><span></span></div><a class="link">About</a>
</li>
<li>
<div class="hole-counter"><span></span></div><a class="link">Gallery</a>
</li>
<li>
<div class="hole-counter"><span></span></div><a class="link">Contact</a>
</li>
</ul>
</div>
这是 javascript 代码
我在控制台中收到此错误 Uncaught TypeError: link.indexOf is not a function at HTMLAnchorElement.click (index.html:97)
翻翻过去那场雪
牧羊人nacy
一只萌萌小番薯
相关分类