1. <div class="content">
    2. <div id="list">
    3. <img src="images/01.png" alt="">
    4. <img src="images/02.png" alt="">
    5. <img src="images/03.png" alt="">
    6. <img src="images/04.png" alt="">
    7. <img src="images/05.png" alt="">
    8. </div>
    9. <button id="prev"></button>
    10. <button id="next"></button>
    11. <div id="btns">
    12. <span class="current"></span>
    13. <span></span>
    14. <span></span>
    15. <span></span>
    16. <span></span>
    17. </div>
    18. </div>
     <script>
            var prev=document.getElementById("prev");
            var next=document.getElementById("next");
            var lists=document.querySelectorAll("#list>img");
            var icons=document.querySelectorAll("#btns>span")
            var index=0;   //记录下标
            next.onclick=function(){
                index++;
                if(index>4){
                    index=0;
                }
                show(index)
            }
            prev.onclick=function(){
                index--;
                if(index<0){
                    index=4;
                }
                show(index)
            }
            /* 重置下标 */
            for(let i=0;i<icons.length;i++){
                icons[i].index=i;
                icons[i].onclick=function(){
                    let currentIndex=this.index;
                    show(currentIndex)
                }
            }
    
            /* 封装 */
            function show(index){
                for(let i=0;i<lists.length;i++){
                    lists[i].style.display="none"
                }
                lists[index].style.display="block"
    
                for(let i=0;i<icons.length;i++){
                    icons[i].classList.remove("current")
                }
                icons[index].classList.add("current")
            }
        </script>