检查是否选中了特定的单选按钮 [英] Check whether specific radio button is checked
本文介绍了检查是否选中了特定的单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
查看jQuery文档后遇到麻烦。我只是想在我的jquery方法中根据某个单选按钮的检查以及是否已选中它来返回true / false
I'm having trouble after looking at the jQuery docs. I'm just trying to return true/false in one my my jquery methods depending on the check of a certain radiobutton and if it's selected or not
事情,但未能正确解决问题:
I've tried several things but have not been able to get this right:
<input type="radio" runat="server" name="testGroup" id="test1" /><label for="<%=test1.ClientID %>" style="cursor:hand" runat="server">Test1</label>
<input type="radio" runat="server" name="testGroup" id="test2" /><label for="<%=test2.ClientID %>" style="cursor:hand" runat="server">Test2</label>
<input type="radio" runat="server" name="testGroup" id="test3" /> <label for="<%=test3.ClientID %>" style="cursor:hand">Test3</label>
在我的方法中,我这样:
and in my method I have this:
return $("input[@name='test2']:checked");
我在 $( input [@ name = 'test2']:checked);
已更新:
示例:
<input type="radio" runat="server" name="radioGroup" id="payPalRadioButton" value="paypalSelected" />
这仍返回未定义:
$("input[@name=radioGroup]:checked").attr('payPalRadioButton');
如果尝试此操作,即使选择单选按钮,也会得到 false:
If I try this, I get 'false' even if I select the radio button:
$('input:radio[name=radioGroup]:checked').val() == 'paypalSelected'
推荐答案
您的选择器不会选择输入字段,如果选择了它返回一个jQuery对象。试试这个:
Your selector won't select the input field, and if it did it would return a jQuery object. Try this:
$('#test2').is(':checked');
这篇关于检查是否选中了特定的单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文