JQuery Select Operation Large Collection

Source: Internet
Author: User

This article summarizes the selection of the text and value;jquery Add/Remove options option for jquery to get Select, and gives a corresponding explanation.

jquery Gets the text and value selected by select:
Syntax Explanation:

 $ ("#select_id"). Change (function  () {//     code ...}); Adds an event for select, triggering  var  checktext=$ ("#select_id") when one of the items is selected. Find ("option:   Selected "). Text (); //  Gets the text  of select selection   var  checkvalue=$ ("#select_id"). Val (); //    var  checkindex=$ ("#select_id"). Get (0). SelectedIndex; //  Gets the index value of the select selection    var  maxindex=$ ("#select_id option:last"). attr ("index"); //  Get Select maximum index value jquery setting select text and value:  

Syntax Explanation:

$ ("#select_id"). Get (0). selectedindex=1;   // Set the Select index value to 1 to select    $ ("#select_id"). Val (4);    // Sets the value of select to 4 for the item   selected true);    // set the text value of select to the item selected   for jquery

jquery Add/Remove option for select:

Syntax Explanation:

 $ ("#select_id"). Append ("<option value= ' value ' >Text</option>"); //  append an option (drop-down)  $ ("#select_id") for select. Prepend ("<option value= ' 0 ' > Please select   </option> "); //    insert an option (first position)  $ ("#select_id option:last") for Select. Remove (); //    $ (" #select_id option[index= ' 0 '] "). Remove (); //    $ (" #select_id option[value= ' 3 ") of the index value 0 in select. Remove (); //    remove option  $ ("#select_id option[text= ' 4") in select Value= ' 3 '. Remove (); //  
for text= ' 4 ' in select

JQuery Select Operation Large Collection

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.