最近在做項目時遇到要在repeater中顯示多個radiobutton并且實現單選功能,于是很自然地就加上了GroupName,但事實是不行的,在repeater中的radiobutton呈現到頁面的時候name會自動加上repeater的id、序列ct100和radiobutton的id,這就直接導致為什么GroupName會失效了。我在網上搜了有很多方法,但是都沒適用的,比如用<input type=radio>、radiobuttonlist等,但是我既然用了radiobutton,就懶得換了,以下是我的代碼實現:
頁面
1 <table> 2 <tr> 3 <asp:Repeater runat="server" ID="repbgs"> 4 <ItemTemplate> 5 <td> 6 <asp:RadioButton runat="server" ID="rdo1" Text='<%# Eval("name") %>' /> 7 </td> 8 </ItemTemplate> 9 </asp:Repeater>10 </tr>11 </table>
后臺就一個綁定過程就不展示了,還有就是jQuery
1 $(':input:radio').click(function () {2 if ($(this).is(':checked')) {3 $(this).is(':checked');4 $(this).parents().siblings().children().removeAttr("checked");5 }6 });以上就是我的簡單實現
|
新聞熱點
疑難解答