<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{
margin:0px;
padding:0;
}
.active{
border:1px solid red;
width:100px;
height:50px;
}
div{
width:900px;
height:350px;
margin-top: 100px;
margin-left:200px;
}
ul{
width:500px;
height:300px;
border:1px solid black;
}
</style>
</head>
<body>
<div>
<input type="text">
<input type="button" value="创建">
<ul>
<li>bb<a href="javascript:;" >删除</a></li>
<li>a<a href="javascript:;">删除</a></li>
<li>aa<a href="javascript:;">删除</a></li>
</ul>
</div>
<script>
window.onload=function(){
var li=document.getElementsByTagName('li');
var a=document.getElementsByTagName('a');
var oUl=document.getElementsByTagName('ul')[0];
for(var i=0;i<a.length;i++){
a[i].onclick=function(){
oUl.removeChild(this.parentNode);
//必须是父节点去调用removeChild()
//this.parentNode是当前节点的父节点
}
}
}
</script>
</body>
</html>