我在HTML表单中有两个单选按钮.当其中一个字段为空时,会出现一个对话框.如何检查是否选择了单选按钮?
看完jQuery文档后我遇到了麻烦.我只是试图在我的jquery方法中返回true/false,具体取决于对某个radiobutton的检查以及是否选中
我已经尝试了几件事,但未能做到这一点:
<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>
Run Code Online (Sandbox Code Playgroud)
在我的方法中我有这个:
return $("input[@name='test2']:checked");
Run Code Online (Sandbox Code Playgroud)
我得到一个未定义的 $("input[@name='test2']:checked");
更新:
例:
<input type="radio" runat="server" name="radioGroup" id="payPalRadioButton" value="paypalSelected" />
Run Code Online (Sandbox Code Playgroud)
这仍然会返回'undefined':
$("input[@name=radioGroup]:checked").attr('payPalRadioButton');
Run Code Online (Sandbox Code Playgroud)
如果我试试这个,即使我选择了单选按钮,我也会"假":
$('input:radio[name=radioGroup]:checked').val() == 'paypalSelected'
Run Code Online (Sandbox Code Playgroud)