Javascript 未捕获引用错误:未定义caiet

Javascript 未捕获引用错误:未定义caiet,javascript,Javascript,我试图验证一些字段和复选框,并最终计算复选框的数量 如果两个值不相同,并且用户需要用复选框填充公式并求和,则我的代码当前将显示一个警报,但我一直收到此错误: Uncaught ReferenceError: caiet is not defined at HTMLButtonElement.<anonymous> (stoc_placi.php?id_order=384&id_sablon=80:731) at HTMLButtonElement.d

我试图验证一些字段和复选框,并最终计算复选框的数量

如果两个值不相同,并且用户需要用复选框填充公式并求和,则我的代码当前将显示一个警报,但我一直收到此错误:

Uncaught ReferenceError: caiet is not defined   
    at HTMLButtonElement.<anonymous> (stoc_placi.php?id_order=384&id_sablon=80:731)  
    at HTMLButtonElement.dispatch (jquery.min.js:3)  
    at HTMLButtonElement.r.handle (jquery.min.js:3)

您应该在函数外部声明
caiet
变量

在函数外部声明
caiet
以全局访问它

let caiet; 
然后删除函数中的所有代码

let caiet = $(el).closest('tbody');
然后在该对话框内初始化
caiet

let caiet;
$('[name^="caiet_tabel"]').change(function () {

    caiet = $(this).closest('tbody');
    if ($(this).closest('tr').find('td:not(".all") input:checked').length == 4) {
        $(this).closest('tr').find('.all').prop('checked', true);
        sumAll(this);
    }
    let index = $(this).parent().index();
    sumRow(this, index);
});
$('.all').click(function () {
    caiet = $(this).closest('tbody');
    sumAll(this);
})

我现在明白了,艾尔不是defined@CristinelToma我又编辑了一遍。你试过了吗?是的,我已经试过了,现在我得到了:
未捕获类型错误:无法读取未定义的属性“find”
@CristinelToma我相信当点击事件从
$('.calculeaza')
发生时会发生这种情况,并且在这个函数内部你正在使用的
caiet
是不存在的。我能看看你是如何实施我的解决方案的吗?@CristinelToma我更新了我的答案。请删除所有的
let caiet=$(el).closest('tbody')内部的
sumAll()