Najpierw myślałem, że jest to możliwe przy użyciu Array.prototype Concat tablic, jak poniżej:
Array.prototype.concat.call(selects, inputs);
Ale to nie działa tak, że zrobiłem e tablice z kolekcji węzeł i concat to. Wygląda na to, że:
(function() {
var inputs = document.getElementsByTagName('input'),
selects = document.getElementsByTagName('select'),
result,
i,
node;
function convert (collection) {
var a = [];
for (var i = 0, length = collection.length; i < length; i++) {
a.push(collection[i]);
}
return a;
}
// concatenation && convertation
result = Array.prototype.concat(convert(inputs), convert(selects));
// traversing
i = result.length;
while(node = result[--i]) {
alert(node.getAttribute('name'));
}
})();
Zapętlasz je w tym samym czasie lub sekwencyjnie? –