为什么不是想要的结果


<!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>
var treesData;
this.treesData=new Array();
//数据结构:编号,父节点编号,是否存在叶子,显示文本,超级链接
this.treesData.push(['1','1',true,'JavaScript参考书','#']);
this.treesData.push(['11','1',false,'前言','#']);
this.treesData.push(['2','2',false,'联系我们','#']);
this.treesData.push(['12','1',false,'绪论','#']);
this.treesData.push(['142','14',false,'第二节','#']);
this.treesData.push(['141','14',false,'第一节','#']);
this.treesData.push(['133','13',false,'第三节','#']);
this.treesData.push(['14','1',true,'第二章','#']);
this.treesData.push(['143','14',false,'第三节','#']);
this.treesData.push(['13','1',true,'第一章','#']);
this.treesData.push(['132','13',false,'第二节','#']);
this.treesData.push(['131','13',false,'第一节','#']);

//删除数组元素,index为下标
Array.prototype.removeBySplice = function(index)
{
if(isNaN(index)||index>this.length){
return false;
}
this.splice(index,1);
}
var theNode;
var flag;
function del(id)
{
alert(id);
for(var i=0;i<this.treesData.length;i++){
if(this.treesData[i][0]==id) //删除自己
{
theNode=this.treesData[i][0];
flag=this.treesData[i][2];
this.treesData.removeBySplice(i);
if(flag){
del(theNode);
}

}else{
if(this.treesData[i][1]==id)
{
theNode=this.treesData[i][0];
flag=this.treesData[i][2];
this.treesData.removeBySplice(i);
if(flag)
{
del(theNode);
}
}
}
}

}
function view(){
alert("数组大小:"+this.treesData.length);
for(var i=0;i<this.treesData.length;i++)
{
alert(this.treesData[i][0]+":"+this.treesData[i][3]);
}

}
</script>
</head>

<body>
<input type="button" value="删除数组" onclick="del(1)"/>
<input type="button" value="数组大小" onclick="view(1)"/>
</body>
</html>

结果为什么会是3,怎么会这样?我想要的是1个元素啊,怎么解决?
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值