使用JQuery检查/取消选中ASP CheckBox

时间:2015-07-22 05:59:10

标签: jquery asp.net checkbox

如何使用JQuery检查/取消选中以下ASP复选框?

<asp:CheckBox ID="cbImg1" CssClass="cbImg1" Checked="true" Visible="false" ClientIDMode="Static" runat="server" Width="130px" ForeColor="#909090" Font-Size="12px" />

2 个答案:

答案 0 :(得分:4)

您的代码: -

<asp:CheckBox ID="cbImg1" CssClass="cbImg1" Checked="true" Visible="false" ClientIDMode="Static" runat="server" Width="130px" ForeColor="#909090" Font-Size="12px" />

在jQuery中,您可以尝试prop(): -

$("#cbImg1").prop('checked', true); //// To check
$("#cbImg1").prop('checked', false); //// To un check

答案 1 :(得分:0)

首先改变你的

<asp:CheckBox ID="cbImg1" CssClass="cbImg1" Checked="true" Visible="false" ClientIDMode="Static" runat="server" Width="130px" ForeColor="#909090" Font-Size="12px" />

  <asp:CheckBox ID="cbImg1" CssClass="cbImg1" Checked="true" style="display:none" ClientIDMode="Static" runat="server" Width="130px" ForeColor="#909090" Font-Size="12px" />

删除Visible =“false”并使其显示无。

然后假设您有按钮,将以下脚本添加到其中。

OnClientClick="buttonClick(); return false;

添加javascript,如...

   <script type="text/javascript">
                function buttonClick() {      

        $("#<%=cbImg1.ClientID %>").prop('checked', true);
        alert('Called');
       }


      </script>

查看警报是否出现......