jquery Gets the text and value selected by select:
Syntax Explanation:
1. $ ("#select_id"). Change (function () {//code ...}); Add an event for Select, which is triggered when one of the items is selected
2. Var checktext=$ ("#select_id"). Find ("option:selected"). Text (); Gets the text selected by the Select
3. Var checkvalue=$ ("#select_id"). Val (); Gets the value selected by select
4. Var checkindex=$ ("#select_id"). Get (0). SelectedIndex; Gets the index value of the Select selection
5. Var maxindex=$ ("#select_id option:last"). attr ("index");
Gets the maximum index value of the Select jquery settings 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); Sets the value of select to 4 for the item selected
3. $ ("#select_id option[text= ' jQuery ']"). attr ("selected", true); Set the text value of select to the item selected for jquery
jquery Add/Remove option entry for select: Syntax explanation:
1. Append an option (drop-down)
2. $ ("#select_id"). Prepend ("<option value= ' 0 ' > Please select </option>"); Insert an option for select (first position)
3. $ ("#select_id option:last"). Remove (); Delete index value in select maximum option (last)
4. $ ("#select_id option[index= ' 0 ']"). Remove (); Delete option with index value 0 in select (first)
5. $ ("#select_id option[value= ' 3 ']"). Remove (); Delete the Option5 of value= ' 3 ' in select. $ ("#select_id option[text= ' 4 ']"). Remove (); Delete option for text= ' 4 ' in select
Http://www.k686.com
jquery Radio value, checkbox value, select Value, Radio selected, CheckBox selected, select selected, and its related 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;radio The second element of a 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 Box checkbox: $ ("#chk1"). attr ("Checked", "");//Do not tick $ ("#chk2"). attr ("Checked", true);//Tick if ($ ("# Chk1 "). attr (' checked ') ==undefined)//Determine if the radio group has been ticked radio: $ (" input[@type =radio] "). attr (" Checked ", ' 2 ');//Set value= 2 items for the current selection 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 option$ ("#sel") to the drop-down box. empty ();/ Empty drop-down box
----------------------------------------------------------------------------------------------------
Traverse option and Add, remove optionfunction changeshipmethod (shipping) {var len = $ ("select[@name =ishiptype] option"). LENGTHIF ( Shipping.value = "CA") {$ ("select[@name =ishiptype] option"). each (function () {if ($ (). val () = = 111) {$ (this). Remove ();}});} else{$ ("<option value= ' 111 ' >ups ground</option>"). AppendTo ($ ("select[@name =ishiptype]"));}}
Get the selected value of the dropdown
$ (#testSelect option:selected '). Text (), or $ ("#testSelect"). Find (' option:selected '). Text (), or $ ("#testSelect"). Val () //////////////////////////////////////////////////////////////////memory is not good 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 ")//option to add a drop-down box
A little explanation: 1.select[@name = ' country '] option[@selected] means the option element with the Name property, and the property value is ' country ' within the Select element with the selected attribute , it can be seen that there is an @ at the beginning of the property is followed by.
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 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) {}//To determine if a tick has been made
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" ><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 related 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 (); select The second element of the drop-down box is the currently selected value $ (' #select_id ') [0].selectedindex = 1;radio The second element of the 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 Box checkbox: $ ("#chk1"). attr ("Checked", "");//Do not tick $ ("#chk2"). attr ("Checked", true);//Tick if ($("#Chk1 "). attr (' checked ') ==undefined)//Determine if the radio group has been ticked radio: $ (" input[@type =radio] "). attr (" Checked ", ' 2 ');//Set value= 2 items for the current selection 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 option$ ("#sel") to the drop-down box. empty ();//Empty drop-down box
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;radio The second element of the radio group is the currently selected value $ (' input[@name =items]). Get (1). checked = true; Get 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 the radio group has been ticked radio: $ ("input[@ Type=radio]). attr ("Checked", ' 2 ');//Set value=2 items as the current Check drop-down box select: $ ("#sel"). attr ("value", '-sel3 ');//Set value=- SEL3 items are currently selected $ ("<option value= ' 1 ' >1111</option><option value= ' 2 ' >2222</option>"). AppendTo ("#sel")//Add option$ ("#sel") to the drop-down box. empty ();//Empty drop-down box
jquery operation Select drop-down box (check, value, assignment, etc.) reprint