jquery operations Drop-down list, text box, check box, Radio box collection

Source: Internet
Author: User

The

 jquery action drop-down list, text box, check box, and Radio box collection. Various actions related to jquery for Drop-down lists, text boxes, check boxes, and Radio boxes. The best way to make records and collections is

Various actions related to jquery for Drop-down lists, text boxes, check boxes, and Radio boxes. The best way to record and collect.   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 () = () {    $ (this). Remove ();    }  });  }else{  $ ("<option value= ' >ups ground</option>"). Appendto ($ ("select[@name =ishiptype]") ); &NBSP}} //Get the selection value of the Drop-down menu $ (#testSelect option:selected '). Text (); or $ ("#testSelect"). Find (' option:selected '). Text (); or $ ("#testSelect"). Val (); A bad memory can be collected under:   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 ();  //Get the selected value of the Drop-down menu var cc3 = $ ('. FORMC select[@name = ' country '] '). attr ("id"); Gets the id attribute value of the selected item for the Drop-down menu $ ("#select"). empty ();/Empty dropdown box//$ ("#select"). html ('); $ ("<option value= ' 1 ' >1111</option>"). Appendto ("#select")//Add drop-down box option   Explain a little bit: 1.select[@name = ' Country '] option[@selected] represents the option element with the selected attribute in the Select element with the name attribute and the value ' country '; you can see 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 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 () {//The check box is generally selected for more than one, so you can cycle output    alert ($ (this). Val ());    });   $ ("#chk1"). attr ("Checked", "")//Do not tick $ ("#chk2"). attr ("Checked", true);/tick if ($ ("#chk1"). attr (' checked ') = = Undefined) {}//To determine whether a check 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>   <!--dropdown box--> <select id= "Selecttest" 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 values, checkbox values, select values, Radio selected, checkbox selected, Select Select, 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; The second element of the radio 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: $ ("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   Multiple-selection box checkbox: $ (" #chk1 "). attr (" Checked "," ");/not tick                 $ ("#chk2"). attr ("Checked", true);/tick                 I F ($ ("#chk1"). attr (' checked ') ==undefined)//Determine whether the check has been ticked   Radio Group Radio: $ ("input[@type =radio]"). attr ("Checked", ' 2 '); /Set value=2 items for the current Check   dropdown box select: $ ("#sel"). attr ("value", '-sel3 ');//Set VALUE=-SEL3 project to current selected       & nbsp     $ ("≪optionvalue= ' 1 ' >1111</option><optionvalue= ' 2 ' > 2222</option> '). Appendto ("#sel")// Add drop-down box option             $ ("#sel"). Empty ()//Empty dropdown box   Gets a set of radio values of the selected item = $ (' Inpu t[@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;   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 contents $ ("#txt"). attr ("value", ' 11 ');/fill content   Multiple-selection box checkbox: $ ( "#chk1"). attr ("Checked", "")//Do not tick $ ("#chk2"). attr ("Checked", true);/tick if ($ ("#chk1"). attr (' checked ') ==undefined) To determine if a check has been made   Radio Group Radio: $ ("input[@type =radio]"). attr ("Checked", ' 2 ');//Set value=2 item is the current check   drop-down box select: $ ("#sel"). attr ("value", '-sel3 ');//Set VALUE=-SEL3 item is 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  

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.