chrome和firefox支持數組的forEach,但不支持對象的forEach,IE啥都不支持
jquery中的$.each(ArrayOrObject,function)既可以遍歷數組又可以遍歷對象
$.each()函數跟$(selector).each(function)是不一樣的
$(selector).each(function(){})
如果each的回調函數function()沒有參數,還可以使用$(this)來訪問,這樣也可以對$(this)的鍵值對進行更改
each的回調函數還可以有參數(key,value),來訪問鍵值對
x={'user':'wyf','password':'haha'} $.each(x,function(k,v){console.log(v)}) wyf haha $.each(x,function(){console.log($(this))}) ["w", "y", "f"] ["h", "a", "h", "a"] $.each(x,function(k,v){console.log(typeof v)}) $.each(x,function(k,v){console.log(typeof $(this))}) $(this)是隨時可以訪問的(即便使用了參數),v是string類型,$(this)是object類型