Analysis of JQuery control Radio Selection Method _ jquery-js tutorial

Source: Internet
Author: User
This article mainly introduces JQuery's method for controlling Radio selection, involving jQuery form operations and mouse event responses. For more information, see the following example. Share it with you for your reference. The details are as follows:

Method 1:

$(function () {   $("#spanNan").click(function () {   $("#Radio1").attr("checked", true);   $("#Radio2").attr("checked", false);   });  $("#spanNv").click(function () {  $("#Radio2").attr("checked", true);  $("#Radio1").attr("checked", false);  });})

Method 2: (Simple Method)

$(function () {  $("#spanNan").click(function () {  //$("#Radio1").attr("checked", true);  //$("#Radio2").attr("checked", false);  $("#Radio1").click();  });  $("#spanNv").click(function () {  //$("#Radio2").attr("checked", true);  //$("#Radio1").attr("checked", false);  $("#Radio2").click();  });})

Female

Summary:

To implement a single choice for the HTML Radio control, for example, to select a male in this example, you must add the name attribute to Radio with the same value. For example, name = "sex ".

Radio is selected by default:

jQuery(document).ready(function(){  $("input[name=targetBlank]:eq(0)").attr("checked",'checked');  $("input[name=status]:eq(0)").attr("checked",'checked');});

When using jquery to obtain the radio value, the most important thing is to master the use of the jquery selector. in a form, we usually need to obtain the value of the selected radio item, therefore, you need to add checked for filtering, such as the following radio items:

1.Jquery gets the radio Value
2.Jquery obtains the checkbox Value
3.Jquery obtains the select Value

To obtain a radio value, you can use the following methods:

$('input[name="testradio"]:checked').val();$('input:radio:checked').val();$('input[@name="testradio"][checked]');$('input[name="testradio"]').filter(':checked');

It's almost complete. If we want to traverse all radio whose name is testradio, the Code is as follows:

$ ('Input [name = "testradio"] '). each (function () {alert (this. value );});

If you want to obtain a specific radio value, such as the Second radio value, write

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.