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NHHJFOEKEYMISDJUKYIYIRJZVDHBKZQVMWFFTHWKPECLFTYJDVLIYITNADJQWGQAEGRNWIOSMSSGRXXDHKYCSBNDJDNUNNCYIXSFPJVORHYCAUHPXRGGKORFKMBBABPDKIETGMCDXBQSYDTNNSNLWIYOOYMAXOOMICTESXPOENRYTYZOXNWKLPQBWZZYSMMPKWAAPTEHBYNMMSPJNPFAQMKECZDSEQRNYLFTSUOHAHVJWMOUDTNXOIXPFUEVZKORWCYUFJMDZBPYOCPNXTBHAGSWTXLBLRGSWAUDCYHXHBXRUPAFCMMYSJFIRKYVTQRCCYEIMVPVGMCJAUVPNFRZFPJHLYQOBTVWKRFAYYERLJZNSBRXBVSWOKJFBAEFGGBHQCWQBFXSKQPZTUIORKGMOSPTMHNNMGKWKNKRUDXICGXDJYYISMDDFFFKFAUYQBLZOVMQNYKNMCGAOSDOLAQKWAANSOEQHRPRRJVVHKESWYDMWYSMAOITDBROPCKDVHHNRQXBKZLXTEMHSMEWLBPJDXUZWVDRUVFXILUOBZMQLTZYEAEVFRQCBBBHVYKZPDPDIZDVTSIIMTGKINTJIQTHLDGKKNROSPQCYIHFCBPHNDCSEYIP

stone310

道理一样,这是简单版.. function getByClass(oParent,className){                              //从oParent里面搜寻className      var arr=new Array();      var obj=oParent.getElementsByTagName("*")                        //从oParent里面调出所有tag for(var i=0;i<obj.length;i++){    if (obj[i].className==className){                                        arr.push(obj[i])    } }      return arr;  }

李晓健

先获取所有标签,然后循环,看哪一个标签的className属性中包含有你要先的那个class;var getElementsByClassName = function (searchClass, node,tag) {     if(document.getElementsByClassName){         var nodes = (node || document).getElementsByClassName(searchClass),result = [];         for(var i=0 ;node = nodes[i++];){             if(tag !== "*" && node.tagName === tag.toUpperCase()){                 result.push(node)             }else{                 result.push(node)             }         }         return result     }else{         node = node || document;         tag = tag || "*";         var classes = searchClass.split(" "),             elements = (tag === "*" && node.all)? node.all : node.getElementsByTagName(tag),             patterns = [],             current,             match;         var i = classes.length;         while(--i >= 0){             patterns.push(new RegExp("(^|\s)" + classes[i] + "(\s|$)"));         }         var j = elements.length;         while(--j >= 0){             current = elements[j];             match = false;             for(var k=0, kl=patterns.length; k<kl; k++){                 match = patterns[k].test(current.className);                 if (!match) break;             }             if (match) result.push(current);         }         return result;     } }
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答