Cases:
Copy Code code as follows:
<select id= "sltlist" name= "List" >
<option value= "1" > John </option>
<option value= "2" > Dick </option>
</select>
Gets the currently selected option value
$ (' #sltList '). Val ()
Gets the text of the currently selected item
$ (' #sltList option[@selected] '). Text (); Gets the currently selected option, text is the literal, and Val is the option value.
or var item = $ ("select[@name = list] option[@selected]"). Text ();
Sets the text to the current selection
$ ("#sltList option[@selected]"). attr ("text", ' John ');
Sets the second element of the Select Drop-down box to the current selected value
$ (' #sltList ') [0].selectedindex = 1;
Set the value=1 item to the current selected item
$ ("#sltList"). attr ("Value", ' 1 ');
$ (' #sltList '). Val (' 1 ');
Option to add a drop-down box
$ ("<option value= ' 3 ' > Harry </option><option value= ' 4 ' > Zhao Liu </option>"). Appendto ("#sltList")
Clear the dropdown box
$ ("Sltlist"). empty ();
Cases:
Events of the time of change
$ ("#testSelect"). Change (function () {//Event happens
JQuery (' option:selected ', this). each (function () {//printed out to multiple values
alert (this.value);
});
});
$ ("#childTypeResult"). Append (HTMLSTR); Is the value added to the HTMLSTR after this ID label.
$ ("#childTypeResult"). HTML (HTMLSTR); is a value that modifies the value of this ID to htmlstr.