js 数组取数据的问题

来源:百度知道 编辑:UC知道 时间:2024/06/25 12:55:59
posx.push(mousePos.x,mousePos.y,table.getCurrRow().id);

是这么存的

再取的时候 for(var i=0;i<posx.length;i++){ }

我怎么来取 3不同的字段呢?

存:
posx.push({x:mousePos.x,y:mousePos.y,id:table.getCurrRow().id});

取:
for(var i=0;i<posx.length;i++)
{
alert(posx[i].x);
alert(posx[i].y);
alert(posx[i].id);
}

相信我一定行的。

你这种写法不规范。。
这样的push和一个一个push的效果是一样的, 但你这样子写让人看的晕
你要拿里面的数据。。
再取的时候
for(var i=0;i<posx.length;i++){
alert(posx[i]);
}