jquery about the value and assignment of the Select box

Source: Internet
Author: User

JQuery ("#select_id"). Change (function () {}); 1. Add an event for SELECT, trigger     var CheckValue = JQuery ("#select_id") when one of the items is selected. val (); 2. Gets the value of the Select selected item  var checktext = JQuery ("#select_id: Selected"). Text (); 3. Gets the text   var checkindex = jQuery ("#select_id") of the Select selected item. attr ("SelectedIndex");//4. Gets the index value of the Select selected item. Or: JQuery ("#select_id"). Get (0). SelectedIndex;  var Maxindex = JQuery ("#select_id: Last"). attr ("index");  //5. Gets the maximum index value of the SELECT, or: JQuery ("#select_id: Last"). Get (0). Index;  jquery ("#select_id"). Get (0). SelectedIndex = 1; 1. Set the Select index value to 1 to select  jquery ("#select_id"). Val (4);  //2. Sets the value of the select value to 4 to select $ ("#select_id"). attr ("value", "Normal"), $ ("#select_id"). Get (0). Value = value;// The value var count=$ ("#select_id") is set for select based on the display value of select. Get (0). options.length;for (Var i=0;i<count;i++) {if ($ ("#select_ ID "). Get (0). Options[i].text = = text)  {$ (" #select_id "). Get (0). options[i].selected = true;       & nbsp  break;  } }   JQuery ("#select_id"). Append ("<option value= ' new ' > New option</option>"); 1. Append an option (drop-down) jQuery ("#select_id") for select. Prepend ("<option value= ' select ' > Please select </option>");  2. Insert an option (first position) jQuery ("#select_id") for select. Get (0). Remove (1);  3. Delete option (second) JQuery with index value 1 in select ("#select_id: Last"). Remove (); 4. Delete the index value in select maximum option (last) jQuery ("#select_id [value= ' 3 ']"). Remove ();   5. Delete option JQuery ("#select_id") for value= ' 3 ' in Select. Empty (); 6. Clear the drop-down list

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.