如何获取已选中的单选按钮的值,jQuery [英] how to get the values of the radio button which has been checked , jquery

查看:61
本文介绍了如何获取已选中的单选按钮的值,jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们能否获得单选按钮的值,只有那些已选中的按钮, 因为我必须实现一个表单,其中有很多单选按钮,所以我如何获取所有已检查的值

can we get the values of the radio buttons , only those which has been checked , cause i have to implement a form in which there are many radio buttons , so how can i get all the values which has been checked what i have to do is

我有13个科目,例如:物理学,数学,生物学..... 学生可以选择任意数量的科目,每个科目都有两个单选按钮,一个是A,另一个是As,

i have 13 subjects like : physics , math , biology ..... and the students can choose any number of subjects , and each subject will have two radio buttons one is A and the another is As ,

那么我如何获取已检查的单选按钮的值? 使用jQuery

so how can i get the values of the radio buttons which has been checked? using jquery

推荐答案

这将循环遍历文档中所有已检查的单选元素:

This would loop through all the radio elements in the document that have been checked:

$('input:radio:checked').each(function() {
    var value = $(this).val();
    // do something with radio or value
});

如果要获取特定无线电组的检查值,请执行以下操作:

If you wanted to get the checked value of a particular radio group, you would do:

var value = $('input:radio[name=myradios]:checked').val();

因此,如果您的HTML是这样的:

So if your HTML was like this:

<input type='radio' name='myradios' value='1'>
<input type='radio' name='myradios' value='2' checked='checked'>
<input type='radio' name='myradios' value='3'>

value为2

这篇关于如何获取已选中的单选按钮的值,jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆