Sample Code of JQuery to determine whether radio is selected and obtain the selected value, jqueryradio

Source: Internet
Author: User

Sample Code of JQuery to determine whether radio is selected and obtain the selected value, jqueryradio

Other radio operations will be added later. Directly upload the code. Do not forget to reference the JQuery package.

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

Comments: var boolCheck = $ ('input: radio [name = "sex"] '). is (": checked"); better, this method is more concise

Is () Checks Matching Element Sets Based on selectors, elements, or jQuery objects. if at least one element matches a given parameter, true is returned.

If garbled characters are stored, we recommend using notepad ++.


Check whether jquery radio is selected

Are you a single radio or multiple radio (for example, judge whether one of the two radio S is selected )?

For example, the Code is as follows:
//////////////////////////////////////// ///////// Script code ///////////////////////// //////////////////////////////
Var val = $ ('input: radio [name = "sex"]: checked'). val (); // obtain the value selected from the object whose name is sex.
If (val = null) {// null indicates that no item is selected.
Alert ("Nothing selected! ");
Return false;
}
Else {// otherwise, the value of the selected item is output (male or female)
Alert (val );
}
//////////////////////////////////////// ////// Code related to some pages ///////////////////////////// ///////////////////
<Input type = "radio" name = "sex" value = "male"/> male
<Input type = "radio" name = "sex... the remaining full text>

How does jquery determine whether radio is selected?

$ (": Radio"). each (function (){
If ($ (this). attr ("checked ")){
Alert ("selected ");
} Else {
Alert ("not selected ");
}
})

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.