<html><head lang="en"><meta charset="UTF-8"><title></title><style>.banner{ width:300pxheight:250pxposition: relativez-index: 100background: skybluemargin:100px autooverflow:hidden } .banner .first{ left:0} .banner a{ width: 100%height: 100%position: absolutedisplay:blocktop:0left:100%} .banner a img{ width: 100%height: 100%} .banner .pre{ position: absoluteleft:0top:120pxbackground: graywidth:30pxheight:30pxborder-radius: 30pxline-height: 30pxtext-align: centeropacity: 0.4z-index: 1000cursor: pointer} .banner .next{ position: absoluteright:0top:120pxbackground: graywidth:30pxheight:30pxborder-radius: 30pxline-height: 30pxtext-align: centeropacity: 0.4z-index: 1000cursor: pointer} .
CSS里面增加这段代码
.subA,.subB {
display: none
}
然后增加这段JS,大功告成
<script>var ul = document.getElementById('box')
ul.addEventListener('click', function (evnet) {
if(evnet.target && evnet.target.nodeName == 'BUTTON'){
var parent = evnet.target.parentNode
var element = parent.getElementsByClassName('sub' + evnet.target.textContent)[0]
if (element.style.display == 'none'|| !element.style.display) {
element.style.display = 'block'
} else {
element.style.display = 'none'
}
}
})
</script>