3 回答
TA贡献51条经验 获得超28个赞
而且你也不用寫那麼多個
<li><img src="" alt=""></li>
<li><img src="" alt=""></li>
<li><img src="" alt=""></li>
<li><img src="" alt=""></li>
</ul>
<ul class="tab">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
寫一個就可以了,然後當點擊數字顯示相應圖片,其他圖片消失就行
TA贡献51条经验 获得超28个赞
<div class="box">
<!-- 左 -->
<ul class="lef">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
<!-- 右 -->
<div class="rig">
<ul class="img">
<li><img src="img/1.jpg" alt="">1</li>
<li><img src="img/2.jpg" alt="">2</li>
<li><img src="img/3.jpg" alt="">3</li>
<li><img src="img/4.jpg" alt="">4</li>
</ul>
<ul class="tab">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</div>
</div>
<script>
var oTab = document.getElementsByClassName('tab')[0].getElementsByTagName('li'),
oImg = document.getElementsByClassName("img")[0].getElementsByTagName("li"),
length = oTab.length;
for(var i=0; i<length; i++){
showImg(i);
}
function showImg(i) {
oTab[i].onclick = function(){
oImg[i].className = "open";
};
}
</script>
添加回答
举报