阅读了jQuery文档后,我遇到了一些问题。我只是想在我的jQuery方法中检查某个单选按钮是否已选择,并根据情况返回true/false。
我尝试了几种方法,但都没有成功:
<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");
上遇到了 undefined 的问题。
更新:
示例:
<input type="radio" runat="server" name="radioGroup" id="payPalRadioButton" value="paypalSelected" />
这仍会返回 'undefined':
$("input[@name=radioGroup]:checked").attr('payPalRadioButton');
如果我尝试这样做,即使我选择了单选按钮,我也会得到“false”:
$('input:radio[name=radioGroup]:checked').val() == 'paypalSelected'