嵌套事件触发器

nested events trigger

本文关键字:触发器 事件 嵌套      更新时间:2023-09-26

有什么方法可以实现此功能,我选择了所有类型的复选框,该复选框选择了类multicheckBox2中的所有复选框,我可以根据全选切换这些复选框。现在,我的类multicheckBox中的每个复选框都有自己的事件,这些事件显示或隐藏一组其他元素并设置其值。假设我的一个复选框是 #expense-租金包含电力。现在我的问题是,当我选中全选时,我想自动触发函数 toggleElectric(),但这并没有发生,因为$("#expense-RentInclusiveOf-Electricity").click(function()点击事件没有绑定,有什么办法我可以将事件 .click 更改为其他内容并使之成为可能?

$("#expense-RentAllUtilites-All").click(function(){
    var status = $(this).attr('checked')?true:false;        
    toggleAllRentals(status);
});
function toggleAllRentals(status) {
    $(".multiCheckBox2 input").each( function() {
        $(this).attr("checked",status);
    });
}
$("#expense-RentInclusiveOf-Electricity").click(function(){       
    toggleElectricity(this);
});
function toggleElectricity($this){
    if($($this).is(':checked')) {
        $("#expense-Electricity").val('0');
        $(".electricity").hide();
    } else {
        $("#expense-Electricity").val('50');
        $(".electricity").show();
    };
}

尝试更改事件:

$("#expense-RentInclusiveOf-Electricity").change(function() {
});