// Traverse option and add or 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 = '000000'> ups ground </option>"). appendto ($ ("select [@ name = ishiptype]");
}
Http://blog.csdn.net/ajaxchen_615/archive/2009/02/12/3878001.aspx>
}
// Obtain the selected value from the drop-down list
$ ('# Testselect option: selected'). Text ();
Or $ ("# testselect"). Find ('option: selected'). Text ();
Or $ ("# testSelect"). val ();
1. drop-down box:
Var C0 = $ (". formc select [@ name = 'country'] option [@ selected] "). text (); // get the text of the selected item from the drop-down menu (note that there is a space in the middle)
Var cc2 = $ ('. formc select [@ name = "country"]'). val (); // obtain the value of the selected item from the drop-down menu.
Var cc3 = $ ('. formc select [@ name = "country"]'). attr ("id"); // obtain the ID attribute value of the selected item from the drop-down menu
$ ("# Select"). empty (); // clear the drop-down box // $ ("# select" example .html ('');
$ ("<Option value = '1'> 1111 </option>"). appendTo ("# select") // Add the option in the drop-down box
A little explanation:
1. select [@ name = 'country'] option [@ selected] indicates that the name attribute exists,
In addition, the select element with the selected attribute in the 'country' select element has the selected attribute;
It can be seen that the attribute is followed by the @ parameter.
2, single region:
$ ("Input [@ type = radio] [@ checked]"). val (); // obtain the value of the selected item of a single sequence (note that there is no space in the middle)
$ ("Input [@ type = radio] [@ value = 2]"). attr ("checked", 'checked'); // set single checked value = 2 to the selected status. (Note that there is no space in the middle)
3. Check box:
$ ("Input [@ type = checkbox] [@ checked]"). Val (); // obtain the value of the first check box.
$ ("Input [@ type = checkbox] [@ checked]"). Each (function () {// Since multiple check boxes are selected, You can output them cyclically.
Alert ($ (this). Val ());
});
$ ("# CHK1"). ATTR ("checked", ''); // do not check
$ ("# CHK2"). ATTR ("checked", true); // check
If ($ ("# CHK1"). ATTR ('checked') = undefined) {}// you can check whether a check has been performed.
Of course, jquery's selector is powerful. There are many other methods.
<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 related to obtain the value of a set of radio selected items
Var item = $ ('input [@ name = items] [@ checked] '). val ();
Obtain the text of the selected select item.
Var item = $ ("select [@ name = items] option [@ selected]"). text ();
The second element in the select drop-down box is the selected value.
$ ('# Select_id') [0]. selectedIndex = 1;
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 ");
Multiple choice box 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", ''); // clear the content
$ ("# Txt"). attr ("value", '11'); // fill in the content
Multiple choice box checkbox: $ ("# chk1"). attr ("checked", ''); // do not check
$ ("# Chk2"). attr ("checked", true); // check
If ($ ("# chk1"). attr ('checked') = undefined) // you can check whether the checked has been checked.
Radio Group radio: $ ("input [@ type = radio]"). attr ("checked", '2'); // set the project with value = 2 as the currently selected item
Drop-down box select: $ ("# sel"). attr ("value", '-sel3'); // set the value =-sel3 project to the currently selected item
$ ("<Optionvalue = '1'> 1111 </option> <optionvalue = '2'> 2222 </option> "). appendTo ("# sel") // Add the option in the drop-down box
$ ("# Sel"). empty (); // clear the drop-down list
Obtains the value of a set of radio selected items.
Var item = $ ('input [@ name = items] [@ checked] '). val ();
Obtain the text of the selected select item.
Var item = $ ("select [@ name = items] option [@ selected]"). text ();
The second element in the select drop-down box is the selected value.
$ ('# Select_id') [0]. selectedIndex = 1;
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 ");
Multiple choice box 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", ''); // clear the content
$ ("# Txt"). attr ("value", '11'); // fill in the content
Multiple choice box checkbox: $ ("# chk1"). attr ("checked", ''); // do not check
$ ("# Chk2"). attr ("checked", true); // check
If ($ ("# chk1"). attr ('checked') = undefined) // you can check whether the checked has been checked.
Radio Group radio: $ ("input [@ type = radio]"). attr ("checked", '2'); // set the project with value = 2 as the currently selected item
Drop-down box select: $ ("# sel"). attr ("value", '-sel3'); // set the value =-sel3 project to the currently selected item
$ ("<Option value = '1'> 1111 </option> <option value = '2'> 2222 </option> "). appendTo ("# sel") // Add the option in the drop-down box
$ ("# Sel"). empty (); // clear the drop-down list