<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function addfn() {
var li = document.createElement("li");
li.innerText = i1.value;
myul.appendChild(li);
}
function insert() {
var li = document.createElement("li");
var i1 = document.getElementById("i1")
li.innerText = i1.value;
myul.insertBefore(li, 上海);
}
function del() {
var i1 = document.getElementById("i1");
var myul = document.getElementById("myul");
if (i1.value == "") {
alert("Please input something!");
} else {
var childNodes = myul.childNodes;
for (var i = childNodes.length - 1; i >= 0; i--) {
if (childNodes[i] == i1.value) {
myul.removeChild(i1.value);
i1.value = null;
return;
}
}
i1.value = null;
alert("Not Found!");
}
}
</script>
</head>
<body>
<input type="text" id="i1">
<input type="button" value="添加" onclick="addfn()">
<input type="button" value="插入" onclick="insert()">
<input type="button" value="删除" onclick="del()">
<hr>
<ul id="myul">
<li id="北京">北京</li>
<li id="上海">上海</li>
<li id="广州">广州</li>
</ul>
</body>
</html>
本人菜鸟刚学没多久,想请教一下大神们
插入功能怎么改成插入到第二个li前面
还有删除功能想根据id名删除却找不到
小弟上网找了半天还是没解决,求大神们帮帮忙...