1. Obtain the selected select value and text. The html code is as follows:
Copy codeThe Code is as follows:
<Select id = "mySelect">
<Option value = "1"> one </option>
<Option value = "2"> two </option>
<Option value = "3"> three </option>
</Select>
You can use the following script code s to obtain the selected value and text
Copy codeThe 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
Copy codeThe Code is as follows:
Var obj = document. getElementById ("mySelect ");
Obj. add (new Option ("4", "4 "));
3. Delete All option options
Copy codeThe Code is as follows:
Var obj = document. getElementById ("mySelect ");
Obj. options. length = 0;
4. delete option
Copy codeThe Code is as follows:
Var obj = document. getElementById ("mySelect ");
Var index = obj. selectedIndex;
Obj. options. remove (index );
5. Modify the option
Copy codeThe 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
Copy codeThe Code is as follows:
Var obj = document. getElementById ("mySelect ");
Obj. parentNode. removeChild (obj); // remove the current object
7. select selected RESPONSE event
Copy codeThe Code is as follows:
$ ("# MySelect"). change (function (){
// Add the operation code to be executed
})