了吾欲前行
2016-03-23 15:33
<!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 arr=document.getElementsByTagName("li")[1];
var arr1=document.createElement("li")
arr1.innerHTML="php"
otest.inserBefore(arr1,arr[1]);
</script>
</body>
</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 otest = document.getElementById("test"); var arr=document.getElementsByTagName("li")[1]; var arr1=document.createElement("li"); arr1.innerHTML="php"; otest.insertBefore(arr1,arr[1]);//你这里的inser,少了个"t"字母!!!拼写,平时多注意! </script> </body> </html>
otest.inserBefore(arr1,arr[1]);中少了"t"?insertBefore
JavaScript进阶篇
468061 学习 · 21891 问题
相似问题