每天一个JavaScript实例-从一个div元素删除一个段落

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>每天一个JavaScript实例-从一个div元素删除一个段落</title>
<style>
	p{
		padding:20px;
		margin:10px 0;
		width:400px;
		background-color:#eef;
	}
</style>
<script>
window.onload = function(){
	var paras = document.getElementsByTagName("p");
	for(var i=0;i<paras.length;i++){
		paras[i].onclick = prun;
	}
}
function prun(){
	var parent = this.parentNode;
	console.log(parent);
	parent.removeChild(this);
	alert("paras" + document.getElementsByTagName("p").length);
}
</script>
</head>

<body>


<div id = "date">
<p>one</p>
<p>two</p>
<p>three</p>
<p>four</p>
<p>five</p>
</div>

</body>
</html>

posted @ 2014-10-25 20:27  phlsheji  阅读(342)  评论(0编辑  收藏  举报