I need help on jQuery
I have a Jso开发者_运维知识库n object in which I would like to fill a drop down list with distinct values selected from a field of my Json object
This should work.
var s = [];
for (var n in obj) {
if (obj.hasOwnProperty(n)) {
s.push("<option value='");
s.push(n);
s.push("'>");
s.push(obj[n]);
s.push("</option>");
}
}
$("select").append(s.join(""));
var myList = $('#select');
for (var n in obj) {
myList.append($('<option></option>').val(obj[n]).text(n));
}
精彩评论