我的asp.net设计编码如下:
<table>
<tr>
<td>
<asp:RadioButton ID="rad" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:RadioButton ID="RadioButton1" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:RadioButton ID="RadioButton2" runat="server" />
</td>
</tr>
</table>
当我运行这个时,我能够选择所有单选按钮..但我只想选择一个......怎么做...?
答案 0 :(得分:5)
像这样分配GroupName属性:
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="Category1" />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="Category1" />
<asp:RadioButton ID="RadioButton3" runat="server" GroupName="Category1" />
我没有测试过这个,但它应该可行。还有一个RadioButtonList控件,您可能需要查看http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.radiobuttonlist(v=vs.110).aspx
有关基本控件的详细信息,请查看单选按钮上的w3c文档:http://www.w3.org/TR/html401/interact/forms.html#radio
答案 1 :(得分:0)
$("#<%RadioButton1.ClientID%>").change(function(){//server control so use ClientID
//when RadioButton1 will change this will fire
});
答案 2 :(得分:0)
你应该为你的单选按钮添加GroupName .. !!
<table>
<tr>
<td>
<asp:RadioButton ID="rad" GroupName="Radio" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:RadioButton ID="RadioButton1" GroupName="Radio" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:RadioButton ID="RadioButton2" GroupName="Radio" runat="server" />
</td>
</tr>
</table>