Home  >  Article  >  Web Front-end  >  Detailed explanation of select operation in jQuery

Detailed explanation of select operation in jQuery

高洛峰
高洛峰Original
2016-12-03 15:09:571026browse

The following is an introduction to the operation of jquery on select. It is very good. The content introduction is as follows:

The html tag of select is as follows:

<select class="xxx" id="yyy"><option></option>...<option></option></select>

1. Set the option with value as "lll" to select

$(&#39;#yyy&#39;).val("lll");或者$(&#39;.xxx&#39;).val("lll")

can be used to let select automatically select an item, such as selecting an item whose value passed from the background is the same as the value of the option

2. Set the text to "lll" to select the option

$(&#39;#yyy&#39;).find("option[text="lll"]").attr("selected","selected");或者$(&#39;。xxx&#39;).find("option[text="lll"]").attr("selected","true");

3. Get the value of the currently selected item

$('#yyy').val(); or $('.xxx').val();

4. Get the text of the currently selected item

$(&#39;#yyy&#39;).find("option:selected").text()或者$(&#39;#yyy option:selected&#39;).text()

The above is the detailed explanation of the select operation in jQuery introduced by the editor


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn