开发者

populate dropdownlist with an array

开发者 https://www.devze.com 2023-03-22 02:52 出处:网络
I have an arrayvar myList = new Array();and I have a drop down @Html.DropDownList(\"yourList\", Model.yourList).

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

精彩评论

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