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

Detailed explanation of select operation in jQuery

高洛峰
Release: 2016-12-03 15:09:57
Original
1068 people have browsed it

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>
Copy after login

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

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

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");
Copy after login

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()
Copy after login

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


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template