簡體   English   中英

中繼器中僅選中一個復選框

[英]Only one checkbox checked in repeater

我有一個帶1個復選框的轉發器,每個項目都有一個。 我想一次只檢查一個。

復選框是asp:checkbox,不知道它是否有區別。 我嘗試了一些jQuery,但似乎沒有用。

 <asp:Repeater runat="server" DataSourceID="SqlDataSource1" ID="repeater1">
  <ItemTemplate>
  <asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged" Checked='<%# Eval("carousel_check")%>'/>
 </ItemTemplate>
 </asp:Repeater>

我試圖給復選框一個cssclass(checked_button),然后給這個腳本。

    $(document).ready(function () {
        $('.checked_button').change(function () {
            if ($(this).is(':checked')) {
                $('.radio-similar').not(this).removeAttr('checked');
            };
        });
    });

ASP.Net Checkbox呈現在span標簽內。

<span class="checked_button">
   <input id="MainContent_Repeater1_CheckBox1_2" 
     type="checkbox" name="ctl00$MainContent$Repeater1$ctl02$CheckBox1">
</span>

因此,選擇器應為.checked_button input 然后取消選中所有復選框,並僅選中觸發點擊事件的復選框。

$(function() {
    $(".checked_button input").click(function () {
        $('.checked_button input').attr("checked", false);
        $(this).prop("checked", true);
     });
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM