Jquery operation selectoption code summary. For more information, see. 1. Obtain the selected select value and text. The html code is as follows:
The Code is as follows:
One Two Three
You can use the following script code s to obtain the selected value and text
The Code is as follows:
$ ("# MySelect"). val (); // obtain the value of the selected record
$ ("# MySelect option: selected"). text (); // obtain the text value of the selected record
2. Use the new Option ("text", "value") method to add option
The Code is as follows:
Var obj = document. getElementById ("mySelect ");
Obj. add (new Option ("4", "4 "));
3. Delete All option options
The Code is as follows:
Var obj = document. getElementById ("mySelect ");
Obj. options. length = 0;
4. delete option
The Code is as follows:
Var obj = document. getElementById ("mySelect ");
Var index = obj. selectedIndex;
Obj. options. remove (index );
5. Modify the option
The Code is as follows:
Var obj = document. getElementById ("mySelect ");
Var index = obj. selectedIndex;
Obj. options [index] = new Option ("three", 3); // change the corresponding value
Obj. options [index]. selected = true; // keep selected
6. Delete select
The Code is as follows:
Var obj = document. getElementById ("mySelect ");
Obj. parentNode. removeChild (obj); // remove the current object
7. select selected RESPONSE event
The Code is as follows:
$ ("# MySelect"). change (function (){
// Add the operation code to be executed
})