【问题标题】:click Server Side Button and Select/Deselect Chechboxes using JQuery单击服务器端按钮并使用 JQuery 选择/取消选择复选框
【发布时间】:2016-08-17 17:28:17
【问题描述】:

我在触发服务器端按钮时遇到问题,我想做类似于this 的操作,但使用服务器端按钮和复选框。它目前不起作用,我不知道为什么?

$(function all() {
      $("<%= btnSelect.ClientID %>").click(function () {

        if (document.getElementById("<%= btnSelect.ClientID %>") == 'Select All') {
            $('.button input').prop('checked', true);
            document.getElementById("<%= btnChkboxSelect.ClientID %>").value = "Unselect All";
        } else {
            $('.button input').prop('checked', false);
            document.getElementById("<%= btnChkboxSelect.ClientID %>").value = "Select All";
        }
    });

});
<body>
  <div id="main">
    <div id="first">
     <asp:Button ID="btnSelect" runat="server" UseSubmitBehavior="false" Text="Select All" OnClientClick="all();" />
      <div class="button">
        <div>
          <asp:CheckBox ID="checbox1" runat="server" />
        </div>
        <div>
          <asp:CheckBox ID="checbox2" runat="server" />
        </div>
         <div>
          <asp:CheckBox ID="checbox3" runat="server" />
        </div>
      </div>
</body>

【问题讨论】:

    标签: javascript jquery html button server-side


    【解决方案1】:

    您在代码中缺少 # 作为 btnSelect 的 id 选择器。

       $(function {
          $("#<%= btnSelect.ClientID %>").click(function () { 
             if($(this).text() == "Select All")
             {
               $('.button input:checkbox').prop('checked', true);
               $(this).text("Unselect All");
             }
             else
             {
               $('.button input:checkbox').prop('checked', false);
               $(this).text("Select All");
             }       
        });
    
    });
    

    【讨论】:

      猜你喜欢
      • 2011-07-17
      • 1970-01-01
      • 1970-01-01
      • 2011-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多