我試圖使用Node Web Toolkit框架中的.each功能迭代數組。而我這樣做,我傳遞數組中的每個元素爲: ie9中的javascript函數參數
arrayName.each(function(ele){
console.log(ele);
//or
console.log(arguments);
});
這給了我null
或空的IE9。任何人都可以告訴我如何通過數組的每個ele作爲參數的函數?或者還有其他方法可以做到這一點嗎?
我試圖使用Node Web Toolkit框架中的.each功能迭代數組。而我這樣做,我傳遞數組中的每個元素爲: ie9中的javascript函數參數
arrayName.each(function(ele){
console.log(ele);
//or
console.log(arguments);
});
這給了我null
或空的IE9。任何人都可以告訴我如何通過數組的每個ele作爲參數的函數?或者還有其他方法可以做到這一點嗎?
'arrayName'變量是怎樣的? nwtjs.each方法迭代一個特殊的節點集合(查找其中的'節點'屬性),所以你不能迭代一個正常的數組。 作爲他們的例子顯示了:http://nwtjs.github.io/nwt/manual.html - 節點集合部分,你首先需要獲得一個節點集合的引用,因此您可以使用。每次迭代它:
// Creating a new collection
var els = n.all('#mymenu li');
// Iterate over each item in the collection
// Receives each element as an argument
els.each(function(el){
console.log(el);
});
在ie9中嘗試,即console.log(els)會給** undefined **; 。 – user2990798
這是直接從資料爲準。你檢查過它嗎?請試試這個代碼。
// Creating a new collection
var els = n.all('#mymenu li');
// Iterate over each item in the collection
// Receives each element as an argument
els.each(function(el){
console.log(el);
});
'n.all( 'div.btn組')每個(函數(ELS){ \t \t的console.log(ELS); \t \t els.on( 'KEYUP',函數(E){ \t \t \t的console.log( 'E ---->',E) \t \t}) \t})' 這裏** **埃爾斯未定義:(僅在IE9 – user2990798
'.each'是一個jQuery功能。 Javascript使用'.forEach'。試試 –