日期:2014-05-16  浏览次数:20447 次

js删除li问题
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function cc(obj){
//alert('aaa');
while(obj.parentNode.nextSlibing){
alert(obj.parentNode.nextSlibing.nodeType);
obj.parentNode.parentNode.removeChild(obj.parentNode.nextSlibing);
}
}
</script>
</head>

<body>
<ul>
<li>
<label>分类1</label>
<select onchange="cc(this)">
<option value="">aaaaaaa </option>
<option value="" >bbbbbb</option>
</select>
</li>
<li>
<label>分类2</label>
<select onchange="cc(this)">
<option value="">cc</option>
<option value="" >dddddd</option>
</select>
</li>

<li>
<label>分类3</label>
<select cc(this)onchange="cc(this)">
<option value="">eeee</option>
<option value="" >ffffffff</option>
</select>
</li>
</ul>
</body>
</html>

改变下拉框的值,删除他后面的li ,这样写为什么删除不了呢?

------解决方案--------------------
function cc(obj){
obj = obj.parentNode.nextSlibing;
while(obj!=null&&!obj.nodeType){
obj = obj.nextSlibing;
}
if(obj!=null)
obj.parentNode.removeChild(obj);
}
------解决方案--------------------
探讨

function cc(obj){
obj = obj.parentNode.nextSlibing;
while(obj!=null&amp;&amp;!obj.nodeType){
obj = obj.nextSlibing;
}
if(obj!=null)
obj.parentNode.removeChild(obj);
}

------解决方案--------------------
HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function cc(obj){
obj = obj.parentNode.nextSlibing;
while(obj!=null&&!obj.nodeType){
obj = obj.nextSlibing;
}
if(obj!=null)
obj.parentNode.removeChild(obj);
}

</script>
</head>

<body>
<ul>
<li>
<label>分类1</label>
<select onchange="cc(this)">
<option value="">aaaaaaa </option>
<option value="" >bbbbbb</option>
</select>
</li>
<li>
<label>分类2</label>
<select onchange="cc(this)">
<option value="">cc</option>
<option value="" >dddddd</option>
</select>
</li>

<li>
<label>分类3</label>
<select onchange="cc(this)">
<option value="">eeee</option>
<option value="" >ffffffff</option>
</select>
</li>
</ul>
</body>
</html>