function getElementsByClassName = function(className, tagName) { //如果浏览器支持getElementsByClassName()就直接返回 if(document.getElementsByClassName){ return document.getElementsByClassName(className) } //否则遍历document文档指定的标签名集合 var children = document.getElementsByTagName(tagName); //此数组用于保存遍历后得到的class元素 var elements = new Array(); for (var i = 0; i < children.length; i++) { var child = children[i]; var classNames = child.className.split(' '); //分割多个class元素 for (var j = 0; j < classNames.length; j++) { if (classNames[j] == className) { elements.push(child); break; } } } return elements; };
代码中var classNames = child.className.split(' ');怎么理解?求解救
arlenhui
相关分类