我想显示当前用户名并启用一个按钮,如果选中了该复选框,但此脚本不起作用..看起来什么也没有发生,即:if 语句没有触发
HTML
<script>
<script>
if($('#chbPurchaseAgree').attr('checked')) {
$('#lblPurchaseAgreedByValue').val($('#hdnCompUserName').val());
$('#btnPurchaseContinue').attr("Enable", true);
}
</script>
<asp:HiddenField ID="" runat="server" ClientIDMode="Static"/> //hidden field is set in code behind
<div class="control-group" style="float: left;">
<asp:CheckBox ID="chbPurchaseAgree" runat="server" ClientIDMode="Static" CssClass="chkbox" Text="I have read this document and agreed to the terms and conditions"/>
</div>
<asp:Label ID="lblPurchaseAgreedByValue" ClientIDMode="Static" runat="server"></asp:Label>
最佳答案
我相信它不起作用,因为在执行时没有复选框。不确定“asp”标签是什么,但我猜这是客户端渲染的某种占位符。
所以我建议在 DOM 准备好时使用一些框架/语言回调来执行 JavaScript。
关于javascript - Jquery脚本:If Checkbox is checked then change the label text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37123297/