1. Dynamically create select
function createSelect(){
var mySelect = document.createElement_x("select");
mySelect.id = "mySelect";
document.body.appendChild(mySelect);
}
2 .Add option option
function addOption(){
//Find objects based on id,
var obj=document.getElementByIdx_x('mySelect');
//Add an option
obj.add(new Option("text","value"));
}
3. Delete all options option
function removeAll(){
var obj=document.getElementByIdx_x('mySelect');
obj.options.length=0;
}
4. Delete an option option
function removeOne(){
var obj=document.getElementByIdx_x('mySelect');
//index, to delete the serial number of the option, here take the serial number of the currently selected option
var index=obj.selectedIndex;
obj. options.remove(index);
}
5. Get the value of option option
var obj=document.getElementByIdx_x('mySelect');
var index=obj.selectedIndex; //Serial number, take the serial number of the currently selected option
var val = obj.options[index].value;
6. Get the text of option option
var obj=document.getElementByIdx_x('mySelect');
var index=obj.selectedIndex; //Serial number, take the serial number of the currently selected option
var val = obj.options[index].text;
7. Modify option option
var obj=document.getElementByIdx_x('mySelect');
var index=obj.selectedIndex; //Serial number, take the serial number of the currently selected option
var val = obj.options[index]=new Option("new text","new value");
8. Delete select
function removeSelect(){
var mySelect = document.getElementByIdx_x("mySelect");
mySelect. parentNode.removeChild(mySelect);
}