开发者

populate dropdownlist with an array

I have an array var myList = new Array(); and I have a drop down

@Html.DropDownList("yourList", Model.yourList). 

How can I fill 开发者_如何转开发the dropdownlist using javascript.


var myList = new Array();

for (i=0; i<myList.length; i++) {
    master.options[master.options.length]=new Option(myList[i].text, myList[i].value);
}

http://www.javascriptkit.com/javatutors/selectcontent.shtml


var myList = new Array();
myList.push({ value: '1', text: 'item 1' });
myList.push({ value: '2', text: 'item 2' });
myList.push({ value: '3', text: 'item 3' });
$('#yourList option').remove();
$.each(myList, function () {
    $('<option/>', {
        value: this.value,
        html: this.text
    }).appendTo('#yourList');
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜