Javascript 未调用复选框的侦听器

Javascript 未调用复选框的侦听器,javascript,checkbox,event-listener,Javascript,Checkbox,Event Listener,在我的Javascript文件中,我有两个不同复选框的侦听器,但当我选中/取消选中它们时,它们不会被调用。以下是复选框的html: <input type="checkbox" class="checkbox" name="ApproverCheckBox" id="@Approver[0]" checked/>@Approver[1]</li> <input type="checkbox" class="checkbox" name="AccessorCheckB

在我的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>
我在测试时向他们添加了警报…有人能帮我解释一下吗。

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


从未调用document ready,因为错误地添加了一个脚本,其中包含一个错误的document ready。

其工作原理该脚本在js FIDLE中工作。HTML是动态创建的吗?我确认它工作正常。您是否正确导入了JQuery库?当您在HTML中创建HTML时,您需要使用@ JeleLP。HTML确实创建了DyrimalLyi,只是在尝试这个过程中,我只需添加您所拥有的函数,然后返回给您,不幸的是,该解决方案不起作用,它不执行侦听器。您可以在创建元素之后尝试创建侦听器。
$(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");
        }

    });

});
    //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");
        }

    });