Example:
Copy codeThe Code is as follows:
<Select id = "sltList" name = "list">
<Option value = "1"> JOHN </option>
<Option value = "2"> Li Si </option>
</Select>
// Obtain the selected option value
$ ('# SltList'). val ()
// Obtain the text of the selected item
$ ('# SltList option [@ selected]'). text (); // obtain the currently selected option. text is text, and val is the option value.
Or var item = $ ("select [@ name = list] option [@ selected]"). text ();
// Set the text to the selected item
$ ("# SltList option [@ selected]"). attr ("text", 'zhang san ');
// Set the second element of the select drop-down box to the selected value.
$ ('# SltList') [0]. selectedIndex = 1;
// Set the project with value = 1 as the currently selected item
$ ("# SltList"). attr ("value", '1 ');
$ ('# SltList'). val ('1 ');
// Add the option in the drop-down list
$ ("<Option value = '3'> Wang Wu </option> <option value = '4'> Zhao Liu </option>"). appendTo ("# sltList ")
// Clear the drop-down list
$ ("SltList"). empty ();
Example:
// Events during change
$ ("# TestSelect"). change (function () {// event generation
JQuery ('option: selected', this). each (function () {// print multiple values
Alert (this. value );
});
});
$ ("# ChildTypeResult"). append (htmlStr); // adds the value of htmlStr after this ID tag.
$ ("# ChildTypeResult" ).html (htmlStr); is the value of modifying this ID to htmlStr.