美文网首页
JavaScript总结(一)

JavaScript总结(一)

作者: 风的低语 | 来源:发表于2018-06-20 14:38 被阅读5次
//          有个数组 元素"a","b","d","b","c","d" 去掉重复元素
            var arr = new Array();
            arr[0] = "a";
            arr[1] = "b";
            arr[2] = "d";
            arr[3] = "b";
            console.log(arr);
            var arr2 = new Array();
            for(var i = 0;i<arr.length;i++){
            arr2[arr[i]]=arr[i];
            }
            console.log(arr2);
<!DOCTYPE html>
<html>

    <head>
        <title>旋转动图</title>
        <meta charset="utf-8" />
        <script>
            window.onload = function() {
                var count = 1;

                function getImg() {
                    for (var i = 2; i < 37; i++) {
                        document.getElementById("showImg").innerHTML +=
                        '<img class="cName" name="name" src="images/red' + i + '.png" style="display: none;" />';
                    }
                }
                getImg();
                function showImg() {
                    var imgs = document.getElementsByClassName("cName");
                    for (var i = 0; i < imgs.length; i++) {
                        imgs[i].style = "display: none;";
                    }
                    imgs[count].style = "display:inline;";
                    count++;
                    if (count == imgs.length) {
                        count = 0;
                    }
                }
                setInterval(showImg, 500); //调用
            }
        </script>
    </head>

    <body>
        <div id="showImg">
            <img class="cName" name="name" src="images/red1.png" style="display:inline;">
        </div>
    </body>

</html>

相关文章

网友评论

      本文标题:JavaScript总结(一)

      本文链接:https://www.haomeiwen.com/subject/jjttuxtx.html