老师我这个批量删除为什么删除的是1,3,5呢?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="box">
<p>我是段落标签1</p>
<p>我是段落标签2</p>
<p>我是段落标签3</p>
<p>我是段落标签4</p>
<p>我是段落标签5</p>
</div>
<script>
var box = document.getElementById('box');
// 批量删除节点
var ps = document.getElementsByTagName('p');
for(var i = 0; i < 3; i++){
box.removeChild(ps[i]);
}
</script>
</body>
</html>13
收起
正在回答 回答被采纳积分+1
1回答

恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星