ITeye博客

循环访问jQuery 中 JSON 的键/值对

liangfeng366 · 2012-06-05 18:19 · jQuery · Web前端 · jQuery · for · each · Markdown

1.jQuery.each() 该方法的定义为jQuery.each( collection, callback(indexInArray, valueOfElement) ) jQuery网站上有下面的例子:


var map = { 
  'flammable': 'inflammable', 
  'duh': 'no duh' 
}; 
$.each(map, function(key, value) { 
  alert(key + ': ' + value); 
});


结果为: flammable: inflammable duh: no duh 2.用for循环


 for (var prop in obj) {
      alert(prop + " is " + obj[prop]);
   }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。