zoukankan      html  css  js  c++  java
  • JS对img进行操作

       <script type="text/javascript">
            var i = 1; var n;
            function showImg() {

                if (document.getElementById('img').getAttribute("src") == "images/1.jpg") {
                    document.getElementById('img').setAttribute("src","images/2.jpg");
                }
                else {
                     document.getElementById('img').setAttribute("src","images/1.jpg");
                }
            }

            function showImg1() {
                document.getElementById('img').setAttribute("src", "images/" + i + ".jpg"); i++;
                if (i > 10)
                {
                    i = 1;
                }
            }


            function show() {
              n=setInterval(showImg1, 500);
            }

            function show1() {
                clearInterval(n);
            }
        </script>

    </head>
    <body>
        <img id="img" alt="" src="images/1.jpg" width="200" height="200" />
        <input id="Button1" type="button" value="换图片" onclick="showImg()" />
        <input id="Button2" type="button" value="切图" onclick="showImg1()" />
        <input id="Button3" type="button" value="轮换" onclick="show()" />
            <input id="Button4" type="button" value="停止轮换" onclick="show1()" />

    </body>
    </html>

  • 相关阅读:
    物理机与虚拟机互通
    error while loading shared libraries: libevent-2.2.so.1: cannot open shared object file: No such file or directory
    DateTime.Now.ToFileTime
    洛谷-P2249 【深基13.例1】查找
    洛谷-P3817 小A的糖果
    洛谷-P3612 [USACO17JAN]Secret Cow Code S
    洛谷-P5019 铺设道路
    洛谷-P2437 蜜蜂路线
    洛谷-P1044 栈
    洛谷-P1255 数楼梯
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3024900.html
Copyright © 2011-2022 走看看