js--select下拉框中的option对象

建立Option对象

var option1 = document.createElement('option');

动态建立Option对象

function createSelect(){ 
    var new_option= document.createElement("select");  
    new_option.id = "mySelect";  
    document.body.appendChild(new_option); 
} 

取得选项option的值

var obj=document.getElementById('mySelect'); 
var index=obj.selectedIndex;     //序号,取当前选中选项的序号 
var val = obj.options[index].value; 

取得选项option的文本

var obj=document.getElementById('mySelect'); 
var index=obj.selectedIndex; //序号,取当前选中选项的序号 
var val = obj.options[index].text; 

修正选项option

var obj=document.getElementById('mySelect'); 
var index=obj.selectedIndex; //序号,取当前选中选项的序号 
var val = obj.options[index]=new Option("文本","值"); 

删除select

function removeSelect(){ 
    var mySelect = document.getElementById("mySelect"); 
    mySelect.parentNode.removeChild(mySelect); 
} 
    原文作者:denson
    原文地址: https://segmentfault.com/a/1190000004873901
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞