Note: The O in option is to be capitalized, otherwise the syntax error
1. Dynamic creation of Select
function Createselect () {
var myselect = document.createelement_x ("select");
Myselect.id = "Myselect";
Document.body.appendChild (Myselect);
}
2. Add Options Option
function AddOption () {
Find objects by ID,
var obj=document.getelementbyidx_x (' Myselect ');
Add an option
Obj.add (New Option ("text", "value"));This only works in IE.
Obj.options.add (New Option ("text", "value")); This compatible with IE and Firefox
}
3. Remove all options Option
function RemoveAll () {
var obj=document.getelementbyidx_x (' Myselect ');
obj.options.length=0;
}
4. Delete an option
function Removeone () {
var obj=document.getelementbyidx_x (' Myselect ');
Index, to remove the ordinal of the option, take the ordinal of the currently selected option
var Index=obj.selectedindex;
Obj.options.remove (index);
}
5. Get the value of option options
var obj=document.getelementbyidx_x (' Myselect ');
var Index=obj.selectedindex; Ordinal, take the ordinal of the currently selected option
var val = obj.options[index].value;
6. Get the text of options option
var obj=document.getelementbyidx_x (' Myselect ');
var Index=obj.selectedindex; Ordinal, take the ordinal of the currently selected option
var val = obj.options[index].text;
7. Modify Options Option
var obj=document.getelementbyidx_x (' Myselect ');
var Index=obj.selectedindex; Ordinal, take the ordinal 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);
}
JavaScript Operation Select