【发布时间】:2011-01-12 19:12:25
【问题描述】:
查看 jQuery 文档后我遇到了麻烦。我只是想在我的 jquery 方法中返回真/假,具体取决于对某个单选按钮的检查以及它是否被选中
我已经尝试了几件事,但未能做到这一点:
<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>
在我的方法中我有这个:
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');
如果我尝试这个,即使我选择了单选按钮,我也会得到“错误”:
$('input:radio[name=radioGroup]:checked').val() == 'paypalSelected'
【问题讨论】:
标签: jquery radio-button