可否根据innerHTML==“HTML”进行判断?
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题文档</title> </head> <body> <ul id="test"><li>JavaScript</li><li>HTML</li></ul> <script type="text/javascript"> var newnode = document.createElement("li"); var otest = document.getElementById("test"); newnode.innerHTML="php"; for(i=0;i<otest.length;i++){ if(otest.childNodes[i].innerHTML=="HTML"){ otest.insertBefore(newnode,otest.childNodes[i]); } } </script> </body> </html>
上述代码试过if条件otest.childNodes[i].innerHTML=="HTML"和otest.childNodes[i].innerHTML!="HTML"都无法插入节点,想问下是哪里出现问题?