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');
});
精彩评论