如何使用JQuery检查/取消选中以下ASP复选框?
<asp:CheckBox ID="cbImg1" CssClass="cbImg1" Checked="true" Visible="false" ClientIDMode="Static" runat="server" Width="130px" ForeColor="#909090" Font-Size="12px" />
答案 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>
查看警报是否出现......