遍历树节点中每层最后一个元素
<script> $(function(){ var element=document.getElementById("div1"); var myArray=new Array(); var len=0; isChildLI(element) for(var i=0;i < myArray.length;i++){ myArray[i].style.color="red"; } function isChildLI(node) { var s=node.childNodes; var clen=s.length-2; console.log(s[0]); for(var i=0;i { var tagname=s[i].nodeName; if(i==clen&&tagname=='LI') { myArray[len]=s[i]; len++; } isChildLI(s[i]); } } }) </script>