jquery Operations Select Dropdown box multiple methods (check, value, assignment, etc.)

Source: Internet
Author: User

Query gets the text and value of the Select selection: Syntax Explanation: 1.   $ ("#select_id"). Change (function () {//code ...}); Adds an event for select, triggering 2 when one of the items is selected.  var checktext=$ ("#select_id"). Find ("option:selected"). Text (); Gets the Select selected text 3.  var checkvalue=$ ("#select_id"). Val (); Gets the value 4 selected by the Select.  var checkindex=$ ("#select_id"). Get (0). SelectedIndex; Gets the index value of the select selection of 5.  var maxindex=$ ("#select_id option:last"). attr ("index"); Gets the maximum index value of the Select jquery setting Select the text and value: syntax Explanation: 1.  $ ("#select_id"). Get (0). selectedindex=1; Set the Select index value to 1 to select 2.   $ ("#select_id"). Val (4); Set the value of select to 4 to select 3.   $ ("#select_id option[text= ' jQuery ']"). attr ("selected", true); Set the text value of the Select to jquery for the item selected jquery Add/Remove option entry for select: Syntax explanation: 1.  $ ("#select_id"). Append ("<option value= ' value ' >Text</option>"); Append an option to the Select (drop-down) 2.  $ ("#select_id"). Prepend ("<option value= ' 0 ' > Please select </option>"); Insert an option (first position) 3 for select.  $ ("#select_id option:last"). Remove (); Delete the index value in select maximum option (last) 4. $ ("#select_id option[index=' 0 ']. Remove (); Delete option (first) 5 with index value 0 in select.  $ ("#select_id option[value= ' 3 ']"). Remove (); Delete option 5 for value= ' 3 ' in select.  $ ("#select_id option[text= ' 4 ']"). Remove (); Delete option text= ' 4 ' in select Http://www.k686.com jquery radio value, checkbox value, select Value, Radio selected, CheckBox selected, select selected,  And its correlation gets the value of a set of radio selected items var item = $ (' input[@name =items][@checked] '). Val ();  Gets the text of the Select selected item var item = $ ("select[@name =items] option[@selected]"). Text ();  The second element of the Select drop-down box is the currently selected value $ (' #select_id ') [0].selectedindex = 1;   The second element of the radio Radio Group is the currently selected value $ (' input[@name =items] '). Get (1). checked = true; Gets the value: text box, text area: $ ("#txt"). attr ("value"), Multi-marquee checkbox:$ ("#checkbox_id"). attr ("value"), Radio Group Radio: $ ("input[@type =radi  o][@checked]). Val ();   Drop-down box select: $ (' #sel '). Val (); Control form elements: text box, text area: $ ("#txt"). attr ("Value", "");//Empty contents $ ("#txt"). attr ("value", ' 11 ');//Fill Content Multi Marquee checkbox: $ ("#chk1"). attr ("Checked", "");//Do not tick $ ("#chk2"). attr ("Checked", true);//Tick if ($ ("#chk1"). attr (' checked ') ==undefined)// Determine if you have ticked the radio Group radio: $ ("input[@type =radio]). attr ("Checked", ' 2 ');//Set value=2 item as the current Check drop-down box select: $ ("#sel"). attr ("value", '-sel3 ');// Set VALUE=-SEL3 items to the currently selected $ ("<option value= ' 1 ' >1111</option><option value= ' 2 ' >2222</option>" ). AppendTo ("#sel")//Add the option $ ("#sel") to the drop-down box. empty ();//Empty drop-down box----------------------------------------------------- -----------------------------------------------//Traverse option and Add, remove option function Changeshipmethod (shipping) {var len = $ ("select[@name =ishiptype] option"). Length if (shipping.value! = "CA") {$ ("select[@name =ishiptype] option"). each ( function () {if ($ (this). val () = = 111) {$ (this). Remove ();});  }else{$ ("<option value= ' 111 ' >ups ground</option>"). AppendTo ($ ("select[@name =ishiptype]"));}} Gets the selected value of the drop-down list $ (#testSelect option:selected '). Text (); or $ ("#testSelect"). Find (' option:selected '). Text (); or $ ("#testSelect"). Val (); A bad memory can be collected under: 1, drop-down box: var cc1 = $ (". FORMC select[@ Name= ' Country '] option[@selected]). Text (); Get the text of the selected item in the drop-down menu (note that there are spaces in the middle) var CC2 = $ ('. FORMC select[@name = "Country"]. Val (); Get the value of the selected item in the drop-down menu var cc3 = $ ('. FORMC select[@name = "Country"]). attr ("id"); Gets the ID property value of the selected item in the drop-down menu ("#select"). empty ();//Empty the drop-down box//$ ("#select"). HTML ("); $ ("<option value= ' 1 ' >1111</option>"). AppendTo ("#select")//Add the drop-down box option to explain it a little bit: 1.select[@name = ' Country '] option[@selected] represents an option element with the Name property, and the value of the property has a selected attribute inside the Select element of ' country '; it can be seen that a @ begins with a property. 2, Radio Box: $ ("input[@type =radio][@checked]"). Val (); Get the value of the selected item in the Radio box (note that there is no space in the middle) $ ("input[@type =radio][@value =2]"). attr ("Checked", ' checked '); Sets the value=2 of the radio box to the selected state. (Note that there is no space in the middle) 3, check box: $ ("input[@type =checkbox][@checked]"). Val (); The value of the first item that gets the check box selected is $ ("input[@type =checkbox][@checked]"). each (function () {////Because the check box is generally selected for more than one, you can loop out the alert ($ (this). val ()); }); $ ("#chk1"). attr ("checked");//Do not tick $ ("#chk2"). attr ("Checked", true);//Tick if ($ ("#chk1"). attr (' checked ') = = Undefined) {}//Determine if it has been ticked of course the jquery selector is powerful. There are many other ways. <script src= "Jquery-1.2.1.js "type=" Text/javascript "></script> <script language=" javascript "type=" Text/javascript "> $ ( Document). Ready (function () {$ (' #selectTest '). Change (function () {//alert ("Hello");//alert ($ ("#selectTest"). attr (" Name ")); $ ("a"). attr ("href", "xx.html"); Window.location.href= "xx.html"; Alert ($ ("#selectTest"). Val ()); Alert ($ ("#selectTest option[@selected]"). text ()); $ ("#selectTest"). attr ("Value", "2"); }); }); </script> <a href= "#" >aaass</a> <!--drop-down box--<select id= "selecttest" name= "Selecttest" > & Lt;option value= "1" >11</option> <option value= "2" >22</option> <option value= "3" >33</ Option> <option value= "4" >44</option> <option value= "5" >55</option> <option value= "6" >66</option> </select> jquery Radio value, checkbox value, select Value, Radio selected, CheckBox selected, select selected, And its correlation gets the value of a set of radio selected items var item = $ (' input[@name =items][@checked] '). Val (); Gets the text of the Select selected item var item = $ ("select[@name =itEMS] option[@selected]). Text (); The second element of the Select drop-down box is the currently selected value $ (' #select_id ') [0].selectedindex = 1; The second element of the radio Radio Group is the currently selected value $ (' input[@name =items] '). Get (1). checked = true; Gets the value: text box, text area: $ ("#txt"). attr ("value"), Multi-marquee checkbox:$ ("#checkbox_id"). attr ("value"), Radio Group Radio: $ ("input[@type =radio [@checked] "). Val (); Drop-down box select: $ (' #sel '). Val (); Control form elements: text box, text area: $ ("#txt"). attr ("Value", "");//Empty contents $ ("#txt"). attr ("value", ' 11 ');//Fill Content Multi Marquee checkbox: $ ("#chk1"). attr ("Checked", "");//Do not tick $ ("#chk2"). attr ("Checked", true);//Tick if ($ ("#chk1"). attr (' checked ') ==undefined)// Determine if you have ticked the radio Group radio: $ ("input[@type =radio]"). attr ("Checked", ' 2 ');//Set value=2 item as the currently selected drop-down box select: $ ("#sel"). attr (" Value ", '-sel3 ');//Set VALUE=-SEL3 item as currently selected $ (" <optionvalue= ' 1 ' & gt;1111</option><optionvalue= ' 2 ' >2222</option& gt; "). AppendTo ("#sel")//Add the option $ ("#sel") of the drop-down box. empty ();//empties the drop-down box to get a set of radio the value of the selected item var item = $ (' input[@name =items][@checked] ' ). Val (); Gets the text of the Select selected item var item = $ ("select[@name =items] option[@selected]"). TexT (); The second element of the Select drop-down box is the currently selected value $ (' #select_id ') [0].selectedindex = 1; The second element of the radio Radio Group is the currently selected value $ (' input[@name =items] '). Get (1). checked = true; Gets the value: text box, text area: $ ("#txt"). attr ("value"), Multi-marquee checkbox:$ ("#checkbox_id"). attr ("value"), Radio Group Radio: $ ("input[@type =radio [@checked] "). Val (); Drop-down box select: $ (' #sel '). Val (); Control form elements: text box, text area: $ ("#txt"). attr ("Value", "");//Empty contents $ ("#txt"). attr ("value", ' 11 ');//Fill Content Multi Marquee checkbox: $ ("#chk1"). attr ("Checked", "");//Do not tick $ ("#chk2"). attr ("Checked", true);//Tick if ($ ("#chk1"). attr (' checked ') ==undefined)// Determine if you have ticked the radio Group radio: $ ("input[@type =radio]"). attr ("Checked", ' 2 ');//Set value=2 item as the currently selected drop-down box select: $ ("#sel"). attr (" Value ", '-sel3 ');//Set VALUE=-SEL3 item as currently selected $ (" <option value= ' 1 ' >1111</option><option value= ' 2 ' >    2222</option> "). AppendTo (" #sel ")//Add the option $ (" #sel ") to the drop-down box. empty ();//Empty drop-down box

jquery Operations Select Dropdown box multiple methods (check, value, assignment, etc.)

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.