Using jquery to manipulate the code for the Select Drop-down list box _jquery

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.