我在网格中有多个复选框。我的代码示例如下:

<asp:Panel ID="FeatureGridViewPanel" runat="server" Visible="true" Width="100%">
    <div class="topline"></div>
    <div class="linebreak"></div>
    <div style="float:left; width:90%;">
        <asp:GridView ID="FeatureListGridView" runat="server" AutoGenerateColumns="False"
        CellPadding="4" ForeColor="#666666" GridLines="None" Width="100%">
            <Columns>
                <asp:TemplateField>
                    <HeaderTemplate>
                        <asp:Label ID="FeatureNameHeaderLabel" runat="server" Text="Feature Name "
                        CssClass="GridViewTH"></asp:Label>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <div style="display: none;">
                            <asp:Label ID="FeatureIDLabel" runat="server" Text='<%#Eval("FeatureID")%>'>' ></asp:Label>
                        </div>
                        <asp:Label ID="FeatureNameLabel" runat="server" CssClass="GridViewLabel"
                        Text='<%#Eval("FeatureName")%>'>' ></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <HeaderTemplate>
                        <asp:Label ID="FeatureStatusHeaderLabel" runat="server" Text="Feature Status"
                        Class="GridViewTH"></asp:Label>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <asp:CheckBox ID="FeatureStatusCheckBox" runat="server" Checked='<%#Eval("isEnabled") %>'
                        />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <EditRowStyle />
        </asp:GridView>
    </div>
    <div class="topline"></div>
    <div class="linebreak"></div>
    <div style="margin:4px; float:right;">
        <asp:Button ID="CancelAllChagesButton" runat="server" Text="Cancel All Changes"
        OnClick="CancelAllChagesButton_Click" CssClass="CCButtonEnabled" />
        <asp:Button ID="SaveAllChangesButton" runat="server" Text="Save All Changes"
        OnClick="SaveAllChangesButton_Click" CssClass="CCButtonEnabled" />
        <asp:Button ID="ChangePlanButton" runat="server" Text="Change Plan" OnClick="ChangePlanButton_Click"
        CssClass="CCButtonEnabled" />
        <asp:Button ID="UpgradeFeatureButton" runat="server" Text="Update Feature"
        OnClick="UpgradeFeatureButton_Click" CssClass="CCButtonEnabled" />
    </div>
</asp:Panel>


我只想在没有更改的情况下禁用SaveAllChangesButton和CancelAllChagesButton。我想在复选框中有更改时启用SaveAllChangesButton和CancelAllChagesButton。为此,我有一个这样的jQuery代码:

  $(document).ready(function () {
      $('[id$=SaveAllChangesButton]').attr('disabled', 'disabled');
      $('[id$=CancelAllChagesButton]').attr('disabled', 'disabled');
      $(".disabled").click(function () {
          return false;
      });
      $('[id$=FeatureStatusCheckBox]').click(function () {

          $('[id$=CancelAllChagesButton]').removeAttr('disabled', 'disabled');
          $('[id$=SaveAllChangesButton]').removeAttr('disabled', 'disabled');

      });
  });


当没有更改时,它工作正常,但是当某些复选框发生更改时,应启用SaveAllChangesButton和CancelAllChagesButton,但在我的情况下,此按钮未启用。
当用户单击CancelAllChagesButton时,则应禁用SaveAllChangesButton和CancelAllChagesButton。我该如何实现?

最佳答案

尝试这个

$(document).ready(function () {
   $('input[id$="SaveAllChangesButton"]').prop('disabled', true);
   $('input[id$="CancelAllChagesButton"]').prop('disabled', true);

   $(".disabled").click(function () { return false; });
   $('input[id$="FeatureStatusCheckBox"]').click(function () {

         $('input[id$="CancelAllChagesButton"]').removeAttr('disabled');
         $('input[id$="SaveAllChangesButton"]').removeAttr('disabled');

   });
});

10-07 13:45