码迷,mamicode.com
首页 > 其他好文 > 详细

^_^getElementsByClassName

时间:2014-10-08 16:55:05      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   for   sp   div   c   

if (!document.getElementsByClassName) {
    document.getElementsByClassNameForMobile = function(search) {
        var d = document, elements, pattern, i, results = [];
        if (d.querySelectorAll) { // IE8
            return d.querySelectorAll("." + search);
        }
        if (d.evaluate) { // IE6, IE7
            pattern = ".//*[contains(concat(‘ ‘, @class, ‘ ‘), ‘ " + search + " ‘)]";
            elements = d.evaluate(pattern, d, null, 0, null);
            while ((i = elements.iterateNext())) {
                results.push(i);
            }
        } else {
            elements = d.getElementsByTagName("*");
            pattern = new RegExp("(^|\\s)" + search + "(\\s|$)");
            for (i = 0; i < elements.length; i++) {
                if ( pattern.test(elements[i].className) ) {
                    results.push(elements[i]);
                }
            }
        }
        return results;
    };
} else {
    document.getElementsByClassNameForMobile = document.getElementsByClassName;
}

 

^_^getElementsByClassName

标签:style   blog   color   io   ar   for   sp   div   c   

原文地址:http://www.cnblogs.com/jzm17173/p/4011081.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!