//深度遍历,将所有节点遍历一遍 function deepOrder(node){ if(!(node == null)){ divList.push(node); for(var i = 0;i < node.children.length;i++){ deepOrder(node.children[i]) } } }
//nodeName nodeValue nodeType <div id="box"> apple <div class="box2"><p></p>猪</div> </div> <!--<button onclick="myFunction()">点我</button>--> <script> var a =document.getElementById("box").childNodes; console.log(a[0].nodeName);//#text console.log(a[1].nodeName);//DIV console.log(a[0].nodeValue);//apple console.log(a[1].nodeValue);//null 只有文本节点才有nodeValue = data // 对于文本节点,nodeValue=文本值 nodeType = 3 // 对于属性节点,nodeValue=属性值 nodeType = 2 // 对于元素节点(闭合标签),nodeValue = null nodeType = 1 </script>
divList[i].firstChild.nodeValue.trim() == val
divList[i].firstChild.data.trim() == val
PS:setInterval(timer)前最好:clearInterval(timer)