Jquery operations drop down list text box check box radio box set of favorites


Various jquery operations on drop-down lists, text boxes, checkboxes, and checkboxes. As the best way to record and collect. **Iterate over options and add and remove options **The 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). The remove ();     }   });   } else {   $(” < The option value = ‘111’ > UPS Ground< / option>” ). AppendTo ($(” select [@ name = ISHIPTYPE] ”));   } } // gets the selected value of the drop-down menu $(# testSelect option: selected ’). The text (); Or $(” # testSelect ”). The find (’ option: selected ’). The text (); Or $(” # testSelect ”). Val (); ////////////////////////////////////////////////////////////////// For those with a bad memory:

1. Drop-down box:

Var cc1     = $(” formc select [@ name = ‘country’] option [@ selected] ”). The text (); // gets the text of the selected item in the drop-down menu (note the space in the middle) Var cc2 = $(’ formc select [@ name = “country”] ’). The val ();     // gets the value of the selected item in the drop-down menu Var cc3 = $(’ formc select [@ name = “country”] ’). The attr (” id ”); // gets the ID attribute value of the selected item in the drop-down menu $(” # select ”). The empty (); // empty the drop-down box //$(“#select”).html(”); $(” < The option value = ‘1’ > 1111 < / option>” ).appendto (“#select”)// add options to the drop-down box

**A little explanation: **Select [@name=‘country’] option[@selected] And the option element with the selected attribute inside the select element of ‘country’; You can see that the one that starts with an @ is followed by a property.

2. Menu: $(” input [@ type = radio] [@ checked] ”). The val ();     // gets the value of the selected item in the marquee (note no space) $(” input [@ type = radio] [@ value = 2] ”). The attr (” checked ”, “checked”); // set the menu value=2 as the selected state.

3. Check box: $(” input [@ type = checkbox] [@ checked] ”). The val (); // gets the value of the first item selected in the check box $(“input[@type=checkbox][@checked]”). Each (function()     Alert ($(this). Val ());     });

$(” # chk1 ”). Attr (” checked ”, ”); / / no box $(” # chk2). Attr (” checked ”, true); / / box If ($(” # chk1 ”). The attr (” checked ”) = = undefined) {} / / determine whether have tick

Of course jquery’s selectors are powerful. There are many other ways.

< Script SRC = “jquery - 1.2.1. Js” type = “text/javascript” > < / script> < Script language = “javascript” type = “text/javascript” > The $(document). Ready (function () { $(” # selectTest ”). Change (function () {             / / alert (” Hello ”);             / / alert ($(” # selectTest ”). Attr (” name ”));             / / $(” a ”.) attr (” href ”, “xx. HTML”);             / / the window. The location. Href = “xx. HTML”;             / / alert ($(” # selectTest ”). Val ());             Alert ($(” # selectTest option [@ selected] ”). The text ());             $(” # selectTest ”). Attr (” value ”, “2”);

}); }); < / script>

< A href = ”#” > Aaass< / a>

< ! — drop-down box —> < Select id = “selectTest” name = “selectTest >” < The option value = “1” > 11 < / option> < The option value = “2” > 22 < / option> < The option value = “3” > 33 < / option> < The option value = “4” > 44 < / option> < The option value = “5” > 55 < / option> < The option value = “6” > 66 < / option> < / select> Jquery radio values, checkbox values, select values, radio selected, checkbox selected, select selected, and related to get the values of a set of selected items of radio Var item = $(’ input [@ name = items] [@ checked] ’). The val (); Gets the text of the selected item in a select 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] ’). The get (1) checked = true;

**Get the value: **Text field: $(”# TXT “).attr(“value”); $(“#checkbox_id”).attr(“value”); Radio set radio: $(” input [@ type = radio] [@ checked] ”). The val (); Select: $(‘#sel’).val();

**Control form elements: **Text field: $(”# TXT “).attr(“value”, ”); // empty the content                               $(” # TXT ”). Attr (” value ”, “11”); // fill in the content

$(“#chk1”).attr(“checked”, ”); / / no box                               $(” # chk2). Attr (” checked ”, true); / / box                               If ($(” # chk1 ”). The attr (” checked ”) = = undefined) / / determine whether have tick

Radio set radio: $(” input [@ type = radio] ”). The attr (” checked ”, ‘2’); // the item with value=2 is the currently selected item

Select: $(“#sel”).attr(“value”,‘-sel3’); // the item with value=-sel3 is the currently selected item                       $(” < The optionvalue = ‘1’ > 1111 < / option> < The optionvalue = ‘2’ > 2222 < / option>” ). AppendTo (“#sel”)// add options to the drop-down box                       $(” # sel ”). The empty (); // empty the drop-down box

Gets the values of a set of selected items of radio Var item = $(’ input [@ name = items] [@ checked] ’). The val (); Gets the text of the selected item in a select 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] ’). The get (1) checked = true;

**Get the value: **Text field: $(”# TXT “).attr(“value”);

$(“#checkbox_id”).attr(“value”);

Radio set radio: $(” input [@ type = radio] [@ checked] ”). The val ();

Select: $(‘#sel’).val();

**Control form elements: **Text field: $(”# TXT “).attr(“value”, ”); // empty the content $(” # TXT ”). Attr (” value ”, “11”); // fill in the content

$(“#chk1”).attr(“checked”, ”); / / no box $(” # chk2). Attr (” checked ”, true); / / box If ($(” # chk1 ”). The attr (” checked ”) = = undefined) / / determine whether have tick

Radio set radio: $(” input [@ type = radio] ”). The attr (” checked ”, ‘2’); // the item with value=2 is the currently selected item

Select: $(“#sel”).attr(“value”,‘-sel3’); // the item with value=-sel3 is the currently selected item $(” < The option value = ‘1’ > 1111 < / option> < The option value = ‘2’ > 2222 < / option>” ). AppendTo (“#sel”)// add options to the drop-down box $(” # sel ”). The empty (); // empty the drop-down box