getElementsbyClassName to find and act on all elements

This question already has an answer here:

  • Loop through an array in JavaScript 35 answers

  • You should use a for loop. To iterate on every element matching your array-like object of elements returned by getElementsByClassName .

    window.onload = function yourFunction(){
        var elements = document.getElementsByClassName('icon');
        if (elements){
          for (var i = 0; i<elements.length; i++){
            elements[i].innerHTML = elements[i].innerHTML.replace(/_s.png/g, ".png");
          }
        }
        setTimeout(yourFunction, 5000);
    }
    
    yourFunction();
    
    链接地址: http://www.djcxy.com/p/24542.html

    上一篇: 从对象数组中检索数组值

    下一篇: getElementsbyClassName可以查找并处理所有元素