大家看看为什么我这个代码去掉break也不会报错,按说会陷入死循环的啊?
<!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 otest = document.getElementById("test");
var li=document.createElement('li');
li.innerHTML='php';
var oChild=otest.childNodes;
for(var i=0;i<oChild.length;i++){
if(oChild[i].innerHTML=='HTML'){
otest.insertBefore(li,oChild[i]);
break;
}
document.write(otest.childNodes.length+',');//没有break的话是5,5,5,6,6,6,
}
</script>
</body>
</html>