how can I give an array as options to select element?

后端 未结 5 1580
南笙
南笙 2020-12-08 15:43

I have a select element on my HTML page. I want to populate it with an array. as we can give an array as dataprovider to comboBox in action script. I do the following

<
5条回答
  •  猫巷女王i
    2020-12-08 16:17

    You can do this:

    var videoSrcArr = new Array("option1","option2","option3","option4","option5"),
        selectEl = document.getElementById('rec_mode');
    
    
    for(var i = 0; i < videoSrcArr.length; i++){
        selectEl.options.add(new Option(videoSrcArr[i], videoSrcArr[i]));
    }                              
    

提交回复
热议问题