[转载]js 遍历数组对象

[转载]js 遍历数组对象
有一个JSON数组如下
all =  {"error":0,"content":[{"name":"北京","value":"1036","is_checked":"checked"},{"name":"上海","value":"1035","is_checked":""},{"name":"天津","value":"1034","is_checked":""},{"name":"重庆","value":"1033","is_checked":""},{"name":"河北","value":"1032","is_checked":""},{"name":"河南","value":"1031","is_checked":""},{"name":"广东","value":"1030","is_checked":""},{"name":"广西","value":"1029","is_checked":""}]}
contents = all.content;
jQuery方法:
           jQuery.each(contents,function(i,n){  //其中i为键 n为值
           write_message += "<input type=‘checkbox‘ name=‘id[]‘ value=‘"+contents[i].value+"‘ "+contents[i].is_checked+" />"+contents[i].name+"&nbsp;";
            });
          
JS方法
            for (var i in contents) {
               write_message += "<input type=‘checkbox‘ name=‘id[]‘ value=‘"+contents[i].value+"‘>";
            }
            
            for (var i=0; i<contents.length; i++) {
                write_message += "<input type=‘checkbox‘ name=‘id‘ value=‘"+contents[i].value+"‘ "+contents[i].is_checked+" />"+contents[i].name+"&nbsp;";
            }
[转载]js 遍历数组对象

[转载]js 遍历数组对象

上一篇:微信小程序 - 获取/修改上一页面数据 getCurrentPages()


下一篇:NODEJS