jquery Gets the text and value of select selected:
Syntax explanation:
1. $ ("#select_id"). Change (function () {//code ...}); Add an event for select that triggers
2. var checktext=$ ("#select_id") when selecting one of the items. Find ("option:selected"). Text (); // Gets the text
3. Var checkvalue=$ ("#select_id") selected by select. Val (); //Get Select Select Value
4. var checkindex=$ ("# select_id "). Get (0) .selectedindex; //Gets the Select index value
5. var maxindex=$ ("#select_id option:last"). attr ("index"); //Get Select Maximum index value
jquery set Select text and value:
Syntax Explanation:
1. $ ("#select_id"). Get (0) .selectedindex=1; //Set the Select index value of 1 to select
2. $ ("#select_id"). Val (4); //Set the item with a value of 4 for Select to select
3. $ ("#select_id option[text= ' jQuery ']"). attr ("selected", True); //Set Select's text value to the JQuery item selected
jquery Add/Remove option for select:
Syntax Explanation:
1. $ ("#select_id"). Append ("<option value= ' value ' >text</option > "); //Append an option (dropdown)
2. $ (" #select_id ") to select. Prepend (" <option value= ' 0 ' > Please choose </option> " ; //Inserts an option (first position) for the Select
3. $ ("#select_id option:last"). Remove (); //Delete index value in select Max option (last one)
4. $ ("#select_id option[index= ' 0 ']"). Remove (); //delete option (first)
5. $ ("#select_id option[ Value= ' 3] "). Remove (); //delete option
5. $ (" #select_id option[text= ' 4 ') of value= ' 3 "in Select). Remove (); // Delete option
for text= ' 4 ' in select:
http://www.cnblogs.com/SAL2928/archive/2008/10/28/1321285.html
jquery Radio value, checkbox value, select Value, Radio selected, CheckBox selected, select selected, and related
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 a radio group is the currently selected value
$ (' input[@name =items] '). Get (1). checked = true;
Get Value:
text box, text area: $ ("#txt"). attr ("value");
Multiple-selection box checkbox:$ ("#checkbox_id"). attr ("value");
Radio Group Radio: $ ("input[@type =radio][@checked]"). Val ();
Dropdown box Select: $ (' #sel '). Val ();
Control form elements:
text box, text area: $ ("#txt"). attr ("Value", "");/empty content
$ ("#txt"). attr ("value", ' 11 ');//fill content
Multi-Marquee checkbox: $ ("#chk1"). attr ("Checked", "");/no tick.
$ ("#chk2"). attr ("Checked", true);/tick
if ($ ("#chk1"). attr (' checked ') ==undefined)//judge whether it has been ticked
Single-select group radio: $ ("input[@type =radio]"). attr ("Checked", ' 2 ');//Set value=2 project is currently selected
Dropdown box Select: $ ("#sel"). attr ("value", '-sel3 ');//Set VALUE=-SEL3 item as current selection
$ ("<option value= ' 1 ' >1111</option><option value= ' 2 ' >2222</option>"). Appendto ("#sel")// Option to add a drop-down box
$ ("#sel"). empty ();//Empty Drop-down box
----------------------------------------------------------------------------------------------------
Traversing option and adding, removing 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= ' >ups ground</option>"). Appendto ($ ("select[@name =ishiptype]");
}
}
Get the dropdown?? Value of Wei Ni x
$ (#testSelect option:selected '). Text ();
or $ ("#testSelect"). Find (' option:selected '). Text ();
or $ ("#testSelect"). Val ();
//////////////////////////////////////////////////////////////////
A bad memory can be collected:
1, dropdown box:
var cc1 = $ (". FORMC select[@name = ' country '] option[@selected]"). Text (); Gets 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 (); Gets the value of the selected item in the Drop-down menu
var cc3 = $ ('. FORMC select[@name = ' country '] '). attr ("id"); Gets the id attribute value of the selected item in the Drop-down menu
$ ("#select"). Empty ()//Empty 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] Represents the Name property,
and the attribute value is the option element with the selected attribute inside the Select element of ' country ';
It can be seen that a @ begins with a property that follows.
2, Radio Box:
$ ("input[@type =radio][@checked]"). Val (); Gets the value of the selected item in the Radio box (note that there are no spaces 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 are no spaces in between)
3, check box:
$ ("input[@type =checkbox][@checked]"). Val (); Gets the value of the first item selected in the check box
$ ("input[@type =checkbox][@checked]"). each (function () {//, because the check box is typically selected for more than one, you can cycle the output
Alert ($ (this). Val ());
});
$ ("#chk1"). attr ("Checked", "");/no tick.
$ ("#chk2"). attr ("Checked", true);/tick
if ($ ("#chk1"). attr (' checked ') ==undefined) {}//judge whether it has been ticked
Of course jquery's selector is powerful. There are many other ways.
<script src= "Jquery-1.2.1.js" type= "text/Web Effects" ></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>
<!--dropdown 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 related to get a set of radio selected values
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;
Get Value:
text box, text area: $ ("#txt"). attr ("value");
Multiple-selection box checkbox:$ ("#checkbox_id"). attr ("value");
Radio Group Radio: $ ("input[@type =radio][@checked]"). Val ();
Dropdown box Select: $ (' #sel '). Val ();
Control form elements:
text box, text area: $ ("#txt"). attr ("Value", "");/empty content
$ ("#txt"). attr ("value", ' 11 ');//fill content
Multi-Marquee checkbox: $ ("#chk1"). attr ("Checked", "");/no tick.
$ ("#chk2"). attr ("Checked", true);/tick
if ($ ("#chk1"). attr (' checked ') ==undefined)//judge whether it has been ticked
Single-select group radio: $ ("input[@type =radio]"). attr ("Checked", ' 2 ');//Set value=2 project is currently selected
Dropdown box Select: $ ("#sel"). attr ("value", '-sel3 ');//Set VALUE=-SEL3 item as current selection
$ ("<optionvalue= ' 1 ' & gt;1111</option><optionvalue= ' 2 ' >2222</option& gt;"). Appendto ("#sel")//option to add a drop-down box
$ ("#sel"). 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 a radio group is the currently selected value
$ (' input[@name =items] '). Get (1). checked = true;
Get Value:
text box, text area: $ ("#txt"). attr ("value");
Multiple-selection box checkbox:$ ("#checkbox_id"). attr ("value");
Radio Group Radio: $ ("input[@type =radio][@checked]"). Val ();
Dropdown box Select: $ (' #sel '). Val ();
Control form elements:
text box, text area: $ ("#txt"). attr ("Value", "");/empty content
$ ("#txt"). attr ("value", ' 11 ');//fill content
Multi-Marquee checkbox: $ ("#chk1"). attr ("Checked", "");/no tick.
$ ("#chk2"). attr ("Checked", true);/tick
if ($ ("#chk1"). attr (' checked ') ==undefined)//judge whether it has been ticked
Single-select group radio: $ ("input[@type =radio]"). attr ("Checked", ' 2 ');//Set value=2 project is currently selected
Dropdown box Select: $ ("#sel"). attr ("value", '-sel3 ');//Set VALUE=-SEL3 item as current selection
$ ("<option value= ' 1 ' >1111</option><option value= ' 2 ' >2222</option>"). Appendto ("#sel")// Option to add a drop-down box
$ ("#sel"). empty ();//Empty Drop-down box