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 textCopy 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 optionCopy codeThe Code is as follows: var obj = document. getElementById ("mySelect ");
Obj. add (new Option ("4", "4 "));
3. Delete All option optionsCopy codeThe Code is as follows: var obj = document. getElementById ("mySelect ");
Obj. options. length = 0;
4. delete optionCopy codeThe Code is as follows: var obj = document. getElementById ("mySelect ");
Var index = obj. selectedIndex;
Obj. options. remove (index );
5. Modify the optionCopy 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 selectCopy codeThe Code is as follows: var obj = document. getElementById ("mySelect ");
Obj. parentNode. removeChild (obj); // remove the current object
7. select selected RESPONSE eventCopy codeThe Code is as follows: $ ("# mySelect"). change (function (){
// Add the operation code to be executed
})