删除指定节点,如为空字符则自动删除下一节点的函数需要点击两下才能删除下一节点,请问问题在哪?
额。。。在最下面。。。
<!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">
//First Method
/*function clearText1() {
var content=document.getElementById("content");
content.removeChild(content.childNodes[5]);*/ // 在此完成该函数
//Second Method
/*function clearText2(){
var content=document.getElementById("content");
var A=content.childNodes[5];
content.removeChild(A);*/
//Compelet Remove Object
/*function compeletRemoveText(){
var content=document.getElementById("content");
var A=content.childNodes[5];
A=null;
content.removeChild(A);*/
//Remove All Object
/*function RemoveAllText() {
var content=document.getElementById("content");
nodel=content.childNodes.length
for(i=0;i<nodel;i++) {
var x=content.removeChild(content.childNodes[0]); }
}*/
//Remove Selected Object
function RemoveSelectedText(){
var content=document.getElementById("content");
var i=document.getElementById("select").value-1;
if(content.childNodes[i]!=1){
content.removeChild(content.childNodes[i].nextSibling);
}
else{
content.removeChild(content.childNodes[i]);
}
}
</script>
<input type="text" id="select">
<button onclick="RemoveSelectedText()">清除节点内容</button>
</body>
</html>
比如输入5,需要点击两下,才能删除“jquery”这个文本,求大神指教