jquery-set of operations on Radio/checkbox

Source: Internet
Author: User

jquery Gets the value of the radio selection

Code$ ("Input[name= ' Radio_name '][checked]"). Val ();//Select the value of the selected radio
$ ("#text_id"). focus (function () {//code ...})//event triggered when object text_id gets focus
$ ("#text_id"). blur (function () {//code ...})//event triggered when object text_id loses focus
$ ("#text_id"). Select ();//Make the Vlaue value of the text box selected
$ ("Input[name= ' radio_name '][value= ' to select Radio Value '").
attr ("checked", true);//Set radio as selected based on value values

jquery Gets the value of the checkbox selection

$ ("Input[name= ' Checkbox_name '][checked]");//Select a collection of selected checkbox elements if you want to
value you need to traverse this collection
$ ($ ("Input[name= ' Checkbox_name '][checked]")).
Each (function () {arrchk+=this.value + ', ';}); /Traverse the collection of selected checkbox elements to get value values
$ ("#checkbox_id"). attr ("checked");//Get the status of a checkbox (there is no selection, return True/false)
$ ("#checkbox_id"). attr ("Checked", true);//Set the status of a checkbox to checked (checked=true)
$ ("#checkbox_id"). attr ("checked", false);//Set a checkbox with a status of unchecked (Checked=false)
$ ("Input[name= ' Checkbox_name ']"). attr
("Checked", $ ("#checkbox_id"). attr ("checked"));//According to the 3,4,5 bar, you can analyze the meaning of this code
$ ("#text_id"). Val (). Split (",");//Returns an array of value values of text as ', ' delimited

The above operation, in fact, is the use of jquery selector, I hope you have a solid grasp of the jquery selector knowledge.

jquery-set of operations on Radio/checkbox

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.