Jquery gets the radio selected value

Source: Internet
Author: User

As Jquery becomes more and more useful, more and more friends are using it. In the Web, because the CheckBox, Radiobutton, DropDownList, and other controls are frequently used, they are related to the operations of these controls in Jquery. The Jquery version is updated quickly, and the code writing has changed a lot. The following Jquery Code is applicable to query1.4 and later versions.

Radio







1. to obtain the selected value, you can: $ ('input: radio: checked '). val (); $ ("input [type = 'Radio ']: checked "). val (); $ ("input [name = 'rd']: checked "). val (); 2. set the first Radio to the selected value: $ ('input: radio: first '). attr ('checked', 'checked'); or $ ('input: radio: first '). attr ('checked', 'true'); Note: attr ("checked", 'checked') = attr ("checked", 'true ') = attr ("checked", true) 3. set the last Radio to the selected value: $ ('input: radio: lay '). attr ('checked', 'checked'); or $ ('input: radio: lae '). attr ('checked', 'true'); 4. set any radio as the selected value based on the index value: $ ('input: radio '). eq (index value ). attr ('checked', 'true'); index value = 0, 1, 2 .... or $ ('input: radio '). slice (1, 2 ). attr ('checked', 'true'); 5. set Radio as the selected Value based on the value $ ("input: radio [Value = http://www.bkjia.com/kf/201110/'rd2']"). attr ('checked', 'true'); or $ ("input [value = http://www.bkjia.com/kf/201110/'rd2']"). attr ('checked', 'true'); 6. delete Radio $ whose Value is rd2 ("input: radio [value = http://www.bkjia.com/kf/201110/'rd2']"). remove (); 7. delete the number of Radio $ ("input: radio "). eq (index value ). remove (); index value = 0, 1, 2 .... for example, delete 3rd Radio: $ ("input: radio "). eq (2 ). remove (); 8. traverse Radio $ ('input: radio '). each (function (index, domEle) {// write code });

DropDownList









1. get selected item: Get the Value of the selected item: $ ('select # sel option: selected '). val (); or $ ('select # sel '). find ('option: selected '). val (); get the Text value of the selected item: $ ('select # seloption: selected '). text (); or $ ('select # sel '). find ('option: selected '). text (); 2. obtain the index value of the selected item: $ ('select # sel '). get (0 ). selectedIndex; 3. obtain the maximum index value of the current option: $ ('select # sel option: la '). attr ("index") 4. get the DropdownList length: $ ('select # sel ') [0]. options. length; or $ ('select # sel '). get (0 ). options. length; 5. set the first option to the selected value: $ ('select # sel option: first '). attr ('selected', 'true') or $ ('select # sel ') [0]. selectedIndex = 0; 6. set the last option to the selected value: $ ('select # sel option: la '). attr ('selected', 'true ')

 

Related Article

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.