1. dynamically create select
Function createselect (){
VaR myselect = Document. createelement (select );
Myselect. ID = myselect;
Document. Body. appendchild (myselect );
}
2. Add Option
Function addoption (){
Search for objects by ID,
VaR OBJ = Document. getelementbyid ('myselect ');
Add an option
OBJ. Add (New Option (text, value ));
}
3. Delete All option options
Function removeall (){
VaR OBJ = Document. getelementbyid ('myselect ');
OBJ. Options. Length = 0;
}
4. delete an option Option
Function removeone (){
VaR OBJ = Document. getelementbyid ('myselect ');
Index. The sequence number of the option to be deleted. The sequence number of the selected option is used here.
VaR Index = obj. selectedindex;
OBJ. Options. Remove (INDEX );
}
5. Obtain the option value.
VaR OBJ = Document. getelementbyid ('myselect ');
VaR Index = obj. selectedindex; No., which is the serial number of the currently selected option.
Var val = obj. Options [Index]. value;
6. Obtain the option text
VaR OBJ = Document. getelementbyid ('myselect ');
VaR Index = obj. selectedindex; No., which is the serial number of the currently selected option.
Var val = obj. Options [Index]. text;
7. Modify Option
VaR OBJ = Document. getelementbyid ('myselect ');
VaR Index = obj. selectedindex; No., which is 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. getelementbyid (myselect );
Myselect. parentnode. removechild (myselect );
}