jquery determines if radio selects and obtains the sample code for the selected value

Source: Internet
Author: User

This article mainly describes the jquery judge radio whether to select and get the selected value of the method, the code is very simple, but very practical, the need for friends can refer to the following

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

?
123456789101112131415161718192021222324252627282930313233343536373839404142434445 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">"http://www.w3.org/1999/xhtml"><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>JQuery radio</title><script type="text/javascript" language="javascript" src="JavaScript/jquery-1.6.1.min.js" ></script><script type="text/javascript" language="javascript">/*------判断radio是否有选中,获取选中的值--------*/$(function(){$("#btnSubmit").click(function(){var val=$(‘input:radio[name="sex"]:checked‘).val();if(val==null){alert("什么也没选中!");return false;}else{alert(val);}var list= $(‘input:radio[name="list"]:checked‘).val();if(list==null){alert("请选中一个!");return false;}else{alert(list);} });});</script><body><form id="form1" ><input type="radio" name="sex" value="男" />男<input type="radio" name="sex" value="女" />女<br /><input type="radio" name="list" value="十分满意" />十分满意<input type="radio" name="list" value="满意" />满意<input type="radio" name="list" value="不满意" />不满意<input type="radio" name="list" value="非常差" />非常差<br /><input type="submit" value="submit" id="btnSubmit" /></form></body>

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

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 if radio selects and obtains the sample code for the selected value

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.