JQuery obtains Radio and CheckBox Value (sample code) _ jquery

Source: Internet
Author: User
This article mainly describes how to obtain Radio from jQuery and the Value selected by CheckBox in detail. If you need it, you can refer to it, I hope to help you $ ("input [name = 'Radio _ name'] [checked]"). val (); // select the Value of the selected Radio
$ ("# Text_id"). focus (function () {// code...}); // event triggered when the object text_id gets the focus
$ ("# Text_id"). blur (function () {// code...}); // triggered when the focus of the object text_id is lost
$ ("# Text_id"). select (); // set the Vlaue value of the text box to the selected status.
$ ("Input [name = 'Radio _ name'] [value = 'value to select the Value of radio '").
Attr ("checked", true); // set Radio to the selected status based on the Value.


JQuery obtains the Value selected by the CheckBox.

$ ("Input [name = 'checkbox _ name'] [checked]"); // select the set of checked checkbox elements. If you want to get the Value, you need to traverse the set.
$ ("Input [name = 'checkbox _ name'] [checked]").
Each (function () {arrChk + = this. value + ',' ;}); // traverses the set of checked CheckBox elements to obtain the Value.
$ ("# Checkbox_id"). attr ("checked"); // gets the status of a CheckBox (true/false if any CheckBox is selected)
$ ("# Checkbox_id"). attr ("checked", true); // set the status of a CheckBox to select (checked = true)
$ ("# Checkbox_id"). attr ("checked", false); // set the status of a CheckBox to unselected (checked = false)
$ ("Input [name = 'checkbox _ name']"). attr
("Checked", $ ("# checkbox_id"). attr ("checked"); // you can analyze the meaning of the code based on 3, 4, and 5.
$ ("# Text_id"). val (). split (","); // returns an array separated ','.

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.