jquery Determines whether radio is selected, gets the selected value

Source: Internet
Author: User

This digest from: http://www.cnblogs.com/xcj1989/archive/2011/06/29/JQUERY_RADIO.html

/*---------------------------jquery Determines whether radio is selected, gets the selected value----------------------------------*/

Additional to the radio operation function, later in the Add. Directly on the code, don't forget to refer to the jquery package

<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>JQuery Radio</title><Scripttype= "Text/javascript"language= "JavaScript"src= "Javascript/jquery-1.6.1.min.js" ></Script><Scripttype= "Text/javascript"language= "JavaScript"> /*------Determine if Radio is selected, gets the selected value--------*/    $(function(){         $("#btnSubmit"). Click (function(){             varVal=$('input:radio[name= "Sex"]:checked'). Val (); if(Val==NULL) {alert ("There's nothing to choose from!"); return false; }            Else{alert (val); }            varList= $('input:radio[name= "List"]:checked'). Val (); if(List==NULL) {alert ("Please select a!"); return false; }            Else{alert (list);     }                     }); });</Script></Head><Body><formID= "Form1" ><inputtype= "Radio"name= "Sex"value= "Male" />male<inputtype= "Radio"name= "Sex"value= "female" />female<BR/><inputtype= "Radio"name= "List"value= "Very Satisfied" />Very Satisfied<inputtype= "Radio"name= "List"value= "Satisfied" />Satisfaction<inputtype= "Radio"name= "List"value= "Not Satisfied" />not satisfied<inputtype= "Radio"name= "List"value= "very poor" />very poor<BR/><inputtype= "Submit"value= "Submit"ID= "Btnsubmit" /></form></Body></HTML>

Comments: Var boolcheck=$ (' input:radio[name= ' Sex "]). Is (": checked "); Better, this method is more concise

Introduction to the jquery is () method http://www.w3school.com.cn/jquery/traversing_is.asp

Is () detects a collection of matching elements based on a selector, element, or JQuery object, and returns true if at least one of these elements matches the given parameter.

If you save after garbled, it is recommended to use notepad++ processing.

jquery Determines whether radio is selected, gets the selected value

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.