开发者

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));
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜