组合对象数组 [英] Combining object arrays

查看:64
本文介绍了组合对象数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有2个对象数组,如:


var txtobj = theform.getElementsByTagName(" input");

var selobj = theform.getElementsByTagName (选择);


我希望迭代它们我想将它们组合起来然后

迭代它们。 />

所以我会在下面做这样的事情,但看起来并不正确。

var bothobj = txtobj + selobj;

for(var i = 0; i< bothobj.length; i ++)

{

做点什么....

}


有什么想法吗?

If I have 2 object arrays like:

var txtobj = theform.getElementsByTagName("input");
var selobj = theform.getElementsByTagName("select");

and i want to iterate over them I''d like to combine them and then
iterate over them.

so I would do something like this below, but that doesn''t look right.
var bothobj = txtobj+selobj;

for( var i=0; i<bothobj.length; i++ )
{
do something....
}

Any thought?

推荐答案

迈克在9/14上说了以下内容/ 2005 4:37 PM:
mike said the following on 9/14/2005 4:37 PM:
如果我有2个对象数组,如:

var txtobj = theform.getElementsByTagName(" input");
var selobj = theform.getElementsByTagName(" select");

我希望迭代它们我想将它们组合起来然后
它对他们感到愤怒。

所以我会做下面这样的事情,但看起来并不正确。
var bothobj = txtobj + selobj;

(var i = 0; I< bothobj.length; i ++)
{
做点什么....

有什么想法?
If I have 2 object arrays like:

var txtobj = theform.getElementsByTagName("input");
var selobj = theform.getElementsByTagName("select");

and i want to iterate over them I''d like to combine them and then
iterate over them.

so I would do something like this below, but that doesn''t look right.
var bothobj = txtobj+selobj;

for( var i=0; i<bothobj.length; i++ )
{
do something....
}

Any thought?




测试它看看。


..concat()


-

兰迪

comp.lang.javascript常见问题 - http://jibbering.com/faq &新闻组周刊



Test it and see.

..concat()

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly


mike写道:
mike wrote:
如果我有2个对象数组,如:

var txtobj = theform.getElementsByTagName(" input");
var selobj = theform.getElementsByTagName(" select");
If I have 2 object arrays like:

var txtobj = theform.getElementsByTagName("input");
var selobj = theform.getElementsByTagName("select");




Bad !!

var txtobj = document.theform.getElementsByTagName(" input")

但是为什么不使用DOM 0?


function checkInputsAndSelects(form){

var f = form.length;

while(f - ){

if(form [f] .type.toLowerCase()==" input"){

//输入内容

}

if(form [f ] .type.toLowerCase()==" select"){

//做选择的东西

}

}

}


Mick


[...]



Bad!!
var txtobj = document.theform.getElementsByTagName("input")

But why not use DOM 0?

function checkInputsAndSelects(form){
var f=form.length;
while(f--){
if(form[f].type.toLowerCase()=="input"){
// do stuff with input
}
if(form[f].type.toLowerCase()=="select"){
// do stuff with select
}
}
}

Mick

[...]


Mick,


为什么这么糟糕?


var txtobj = document.theform.getElementsByTagName(" input" ;)


这是因为你认为它只会得到< input ..>但不是< INPUT ...>


Mike

Mick,

Why is this bad?

var txtobj = document.theform.getElementsByTagName("input")

Is it because you think it only gets <input ..> but not <INPUT ...>

Mike


这篇关于组合对象数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆