关于删除一行的实现,我这个点击一下删除一行在删除最后一行时不知道问什么要点击2次,不知道哪位大神能解答一下?
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head>
<body>
<div id="content">
<h1>html</h1>
<h1>php</h1>
<h1>javascript</h1>
<h1>jquery</h1>
<h1>java</h1>
</div>
<script type="text/javascript">
function clearText()
{
var mynode=document.getElementById("content");
for(var i=mynode.childNodes.length-1;i>=0;i--)
{
var x=mynode.removeChild(mynode.childNodes[i]);
}
}
function clearone(){
var mynode=document.getElementById("content");
//此处用到的是继续循环:continue
for(i=0;i<mynode.childNodes.length;i++)
{
if(mynode.childNodes[i].nodeType!=1)
{
continue;
}
var x=mynode.removeChild(mynode.childNodes[mynode.childNodes.length-1]);
}
}
</script>
<button onclick="clearText()">清除节点内容</button>
<input type="button" value="删除一行" onclick="clearone()" />
</body>
</html>