{"options":[ {"value" : "130200","text" : "唐山"},
{"value" : "130300","text" : "秦皇岛"},
{"value" : "130400","text" : "邯郸"},
{"value" : "130500","text" : "邢台"},
{"value" : "130600","text" : "保定"},
{"value" : "130700","text" : "张家口"},
{"value" : "130800","text" : "承德"},
{"value" : "130900","text" : "沧州"},
{"value" : "131000","text" : "廊坊"},
{"value" : "131100","text" : "衡水"} ]}如何把上面的数据添加到下拉菜单中去
javascript或者jquery实现
{"value" : "130300","text" : "秦皇岛"},
{"value" : "130400","text" : "邯郸"},
{"value" : "130500","text" : "邢台"},
{"value" : "130600","text" : "保定"},
{"value" : "130700","text" : "张家口"},
{"value" : "130800","text" : "承德"},
{"value" : "130900","text" : "沧州"},
{"value" : "131000","text" : "廊坊"},
{"value" : "131100","text" : "衡水"} ]}如何把上面的数据添加到下拉菜单中去
javascript或者jquery实现
$.each(data,function(i,n){
$("#sel")[0].options.add(new Option(n.text,n.value));
})
$.each(data.options,function(i,n){ $("#sel")[0].options.add(new Option(n.text,n.value));
})
要看不懂他这个循环
就这么写 var t= {...};
if (t.options.length > 0) {
var amount = document.getElementById("ddl_amount");
for (var i = 0; i < t.paccoument.length; i++) {
amount.options.add(new Option(t.options[i].text, t.options[i].value));
}
}