日期:2014-05-16  浏览次数:20420 次

js查找某元素中的所有图片地址
 function findImg() {
                    var charImg = document.all("chartImg").getElementsByTagName("img");
                    var imgURLs = "";
                    for (var i = 0; i < charImg.length; i++) {
                        var imgPath = getImgPath(charImg[i].src);
                        var imgNames=getImgNames(imgPath);
                        if (imgNames!= "vt2.png") {
                            imgURLs += imgNames;  //如果用document.getElementsByTagName("img")[i].src;每取一个图片地址就会对全部图片查找一次,这样效率比较低,还是储存在imgs中比较好!
                        }
                    }
                  alert( imgURLs);
                 
                }