前端新人小白求助!!!js总是报错:not of type 'Node'!!! 10
点击#option_l里的某一个div删除他总是报UncaughtTypeError:Failedtoexecute'removeChild'on'Node':param...
点击#option_l里的某一个div 删除他 总是报Uncaught TypeError: Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'.这个错误 求大神指点
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>百度DOM操作</title>
<style>
*{margin: 0;padding: 0;}
li{list-style: none;}
#top{width: 1000px;height: 60px;border: 1px solid #000;border-bottom:none;margin: 200px auto 0 auto;}
#box{width: 1000px;height: 400px;border: 1px solid #000;margin: 0 auto;}
.box_li{width: 100px;height: 100px;background: red;}
#btn{width: 100px;height: 30px;}
/*#box_btn{position: relative;}*/
#option{display: none;width: 800px;height: 200px;border: 1px solid #000;margin: 0 auto;}
#option_l{width: 50%;float: left;}
#option_r{width:50%;float: left;}
</style>
</head>
<body onload="begin()">
<div id="top">
<ul>
<li>我的关注</li>
</ul>
</div>
<div id="box">
<ul id="box_ul"></ul>
<div id="box_btn">
<input type="button" name="自定义" id="btn" value="+自定义" />
<div id="option">
<div id="option_l">
<span>已关注</span>
<div style="cursor: pointer;">我的导航</div>
<div style="cursor: pointer;">我的导航</div>
</div>
<div id="option_r">
<span>未关注</span>
<div style="cursor: pointer;">我的星座</div>
</div>
</div>
</div>
<script type="text/javascript">
function begin(){
var oOption=document.getElementById('option');
var oBtn=document.getElementById('btn');
oBtn.onclick=function(){
oOption.style.display='block';
};
var oOtionl=document.getElementById('option_l');
var oOtionl_div=oOtionl.getElementsByTagName('div');
for (var i=0;i<oOtionl_div.length;i++) {
oOtionl_div[i].onclick=function(){
oOtionl.removeChild('oOtionl_div[i]');
};
}
}
</script>
</div>
</body>
</html>
var textul=document.getElementById('box_ul');
oBtn.onclick=function(){
oOption.style.display='block';
var para=document.createElement('li');
textul.appendChild(para);
var textli=textul.getElementsByTagName('li');
for (var i=0;i<textli.length;i++) {
textli[i].className='box_li';
}
}; 展开
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>百度DOM操作</title>
<style>
*{margin: 0;padding: 0;}
li{list-style: none;}
#top{width: 1000px;height: 60px;border: 1px solid #000;border-bottom:none;margin: 200px auto 0 auto;}
#box{width: 1000px;height: 400px;border: 1px solid #000;margin: 0 auto;}
.box_li{width: 100px;height: 100px;background: red;}
#btn{width: 100px;height: 30px;}
/*#box_btn{position: relative;}*/
#option{display: none;width: 800px;height: 200px;border: 1px solid #000;margin: 0 auto;}
#option_l{width: 50%;float: left;}
#option_r{width:50%;float: left;}
</style>
</head>
<body onload="begin()">
<div id="top">
<ul>
<li>我的关注</li>
</ul>
</div>
<div id="box">
<ul id="box_ul"></ul>
<div id="box_btn">
<input type="button" name="自定义" id="btn" value="+自定义" />
<div id="option">
<div id="option_l">
<span>已关注</span>
<div style="cursor: pointer;">我的导航</div>
<div style="cursor: pointer;">我的导航</div>
</div>
<div id="option_r">
<span>未关注</span>
<div style="cursor: pointer;">我的星座</div>
</div>
</div>
</div>
<script type="text/javascript">
function begin(){
var oOption=document.getElementById('option');
var oBtn=document.getElementById('btn');
oBtn.onclick=function(){
oOption.style.display='block';
};
var oOtionl=document.getElementById('option_l');
var oOtionl_div=oOtionl.getElementsByTagName('div');
for (var i=0;i<oOtionl_div.length;i++) {
oOtionl_div[i].onclick=function(){
oOtionl.removeChild('oOtionl_div[i]');
};
}
}
</script>
</div>
</body>
</html>
var textul=document.getElementById('box_ul');
oBtn.onclick=function(){
oOption.style.display='block';
var para=document.createElement('li');
textul.appendChild(para);
var textli=textul.getElementsByTagName('li');
for (var i=0;i<textli.length;i++) {
textli[i].className='box_li';
}
}; 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询