【发布时间】:2014-01-14 06:31:33
【问题描述】:
ASP.NET 4.51 网络表单、jQuery 2.0.3
<div class="row">
<div class="col-xs-3 col-sm-3 col-md-3">
<div class="checkbox">
<label>
<asp:CheckBox ClientIDMode="Static" ID="chkAgree" runat="server" />I Agree
</label>
</div>
<br/>
<asp:CustomValidator ID="cfvAgree" runat="server" ValidationGroup="Default" ErrorMessage="Agree to terms and conditions." ClientValidationFunction="CheckTermsAndConditions" CssClass="label label-danger"></asp:CustomValidator>
</div>
还有java脚本:
<script type="text/javascript">
function CheckTermsAndConditions(aSource, aArgs) {
if ($('#checkbox').prop('checked')) {
console.log("true");
aArgs.IsValid = true;
} else {
console.log("false");
aArgs.IsValid = false;
}
}
</script>
问题是即使复选框被选中,它总是返回 false。我确定我在这里遗漏了一些明显的东西,但它是什么?
【问题讨论】:
-
看起来你的复选框 id 是错误的。试试
$('#chkAgree').prop('checked') -
@ArunPJohny 你是对的。这里眼睛累了。谢谢。
标签: c# jquery asp.net webforms