首页 > 代码库 > js settimeout

js settimeout

参考自这篇文章

关键:settimeout要放到遍历的外边(ele为数组),才能使得循环遍历生效。

  function getElementsByClassName(n) {        var classElements = [], allElements = document.getElementsByTagName(‘*‘);        for (var i = 0; i < allElements.length; i++) {            if (allElements[i].className == n) {                classElements[classElements.length] = allElements[i];            }        }        return classElements;    }    function loaded() {        var ele = getElementsByClassName(‘myScrollbarH‘);        setTimeout(function () {            for (i = 0; i < ele.length; i++) {                var element = ele[i].id;                //alert(element);                new iScroll(element, {                    scrollbarClass: ‘myScrollbar‘                });            }        }, 100);    }

 

js settimeout