सबसे पहले, मैंने सोचा था कि इस Array.prototype का उपयोग कर सरणियों concat करने के लिए, इस तरह संभव है:
Array.prototype.concat.call(selects, inputs);
लेकिन यह काम नहीं करता है, ताकि मैं नोड संग्रह और concat से एक सरणियों कर दिया है यह। कि ऐसा लगता है:
(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'));
}
})();
स्रोत
2009-05-27 09:53:21
दोनों एक ही समय में या क्रमशः लूपिंग? –