未调用复选框的侦听器



在我的Javascript文件中,我有一个用于两个不同复选框的侦听器,但是当我选中/取消选中它们时,它们不会被调用。以下是复选框的 html:

<input type="checkbox" class="checkbox" name="ApproverCheckBox" id="@Approver[0]" checked/>@Approver[1]</li>
<input type="checkbox" class="checkbox" name="AccessorCheckBox" id="@entry[0]" checked/>@entry[1]</li>

以下是 Javascript 文件中未执行的部分:

$(document).ready(function () {
    //listener for accessor checkbox
    $('input[name=ApproverCheckBox]').change(function () {
        if ($(this).is(':checked')) {
            //AddAccessor(this.id);
            alert("it is working");
        }
        else {
            //RemoveAccessor(this.id);
            alert("it is working");
        }
    });
    //listener for approver checkbox
    $('input[name=ApproverCheckBox]').change(function () {
        if ($(this).is(':checked')) {
            //AddApprover(this.id);
            alert("it is working");
        }
        else {
            //RemoveApprover(this.id);
            alert("it is working");
        }
    });
});

我在测试时向他们添加了警报...有人可以说一些光芒吗?

试试这个:(添加 HTML 后放置)

    //listener for accessor checkbox
    $(document).on('change','input[name=ApproverCheckBox]', function() {
        if ($(this).is(':checked')) {
            //AddAccessor(this.id);
            alert("it is working");
        }
        else {
            //RemoveAccessor(this.id);
            alert("it is working");
        }
    });
    //listener for approver checkbox
    $(document).on('change','input[name=ApproverCheckBox]', function() {
        if ($(this).is(':checked')) {
            //AddApprover(this.id);
            alert("it is working");
        }
        else {
            //RemoveApprover(this.id);
            alert("it is working");
        }
    });

从未调用文档就绪,因为错误地添加了包含文档就绪的脚本,其中有错误。

最新更新