zoukankan      html  css  js  c++  java
  • 点击小圆圈切换图片(基础)

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title></title>
        <style>
    
        input{ width: 15px; height: 15px; background-color: #ccc; border-radius: 100%; border-style: none; }
        input:hover{ background-color:#333; }
        img{ width: 200px; height: 300px; }
        </style>
    }
    
    <script type="text/javascript">
     window.onload = function(){
       var arrImg = ['img/1.png','img/2.png','img/3.png','img/4.png'],
           aBtn = document.getElementsByTagName('input'),
           oImg = document.getElementById('img');
    
           oImg.src = arrImg[0]
           for (var i = 0; i < aBtn.length; i++) {
            aBtn[i].index = i; 
               aBtn[i].onclick = function(){
                   
                for (var j = 0; j < aBtn.length; j++) {
                    aBtn[j].style.backgroundColor = '#ccc'
                }//在点击按钮之前先让所有按钮颜色复原,这样就可以实现点击别的按钮时上一个按钮复原的效果
                oImg.src = arrImg[this.index];
                aBtn[this.index].style.backgroundColor = 'red';
               }
           }
     }
    </script>
    </head>
    <body>
    <img id="img" src="">
    <input type="button" name="" value="">
    <input type="button" name="" value="">
    <input type="button" name="" value="">
    <input type="button" name="" value="">
    </body>
    </html>

  • 相关阅读:
    js--获得当前系统时间
    关于react记录
    循环运用记录
    react native环境的搭建
    video,audio的使用细则
    mongoDB 将mongodb添加到服务
    react 全选和全不选
    人生那么多不确定,你怕什么
    select样式的重写
    关于动态插入出现undefined
  • 原文地址:https://www.cnblogs.com/zhangli1021/p/7825733.html
Copyright © 2011-2022 走看看