qq_伏特加_0
2016-09-18 16:50
<!DOCTYPE HTML>
<html>
<head>
<title>无标题文档</title>
</head>
<body>
<ul id="test"><li>JavaScript</li><li>HTML</li></ul>
<script type="text/javascript">
var otest = document.getElementById("test");
var node;//内容为HTML的标签
var newNode = document.createElement("li");
newNode.innerHTML = "PHP";
var i = 0;
while(otest.childNodes[i]){
if(otest.childNodes[i].innerHTML == "HTML"){
node = otest.chhildNodes[i];
break;
}
i++;
}
otest.insertBefore(newNode,node);
</script>
</body>
</html>
node = otest.chhildNodes[i];
chhild 多打h 打错字注意检查不要乱挂
while(otest.childNodes[i]){
if(otest.childNodes[i].innerHTML == "HTML"){
node = otest.chhildNodes[i];
break;
}
i++;
}
otest.childNodes[i].innerHTML == "HTML" 改为otest.childNodes[i].value== "HTML"
node = otest.chhildNodes[i];
JavaScript进阶篇
468194 学习 · 21891 问题
相似问题