做轮播图,之前几个轮播图的按钮一直好好的,到了下边这个,获取按钮后click事件不能触发,不知道为什么,求解,感谢!!!
如图,可以获取到按钮,但是无论怎么点击,控制台什么内容都没有
HTML
<ul class="goods-list">
<a href="javascript:;" class="img-list-btn">
<i class="iconfont"></i>
</a>
<a href="javascript:;" class="img-list-btn">
<i class="iconfont"></i>
</a>
<li>
<a href="javascript:;">
<img src="./img/carousel/1/1.jpg" class="transparent">
<span>照相机</span>
<span>
<span>¥</span><strong>139.00</strong><del>¥439.00</del>
</span>
</a>
</li>
<li>
<a href="javascript:;">
<img src="./img/carousel/1/1.jpg" class="transparent">
<span>照相机</span>
<span>
<span>¥</span><strong>139.00</strong><del>¥439.00</del>
</span>
</a>
</li>
JS
let prev03 = document.getElementsByClassName("goods-list")[0].getElementsByClassName("img-list-btn")[0];
let next03 = document.getElementsByClassName("goods-list")[0].getElementsByClassName("img-list-btn")[1];
console.log(prev03);
prev03.addEventListener("click",click05);
next03.addEventListener("click",click06);
function click05(){
console.log("触发了");
}
function click06(){
console.log("触发了");
}
1、看下事件绑定的时候按钮是否存在
2、看下按钮是否被图片遮挡