javascript 通过class来获取元素方法

javascript 通过class来获取元素方法

       function getByClass(classname){

                var nodes = document.getElementsByTagName('*'),

                     ret=[];

                for(var i=0;i

                       if(hasClass(nodes[i],classname))

                          ret.push(nodes[i]);

                }

                return ret;

            }

            function hasClass(node,className){

                var names = node.className.split(/\s+/);

                for(var i=0;i

                    if(names[i]==className)

                        return true;

                }return false;

            }

你可能感兴趣的:(javascript 通过class来获取元素方法)