gpt4 book ai didi

javascript - jquery on() 方法超出最大调用堆栈大小

转载 作者:行者123 更新时间:2023-11-29 15:24:33 25 4
gpt4 key购买 nike

为什么我会收到此错误:

Uncaught RangeError: Maximum call stack size exceeded

这是我的代码:

$(document).on('keypress focusout', '.checklist-item-input', function (e) {
if (e.which == 13 || e.type == 'focusout') {
$('.checklist-item').removeClass('edit');
$(this).siblings('.checklist-item-detail').text($(this).val());
$(this).blur();
$('.checklist-item-detail').each(function () {
if (!$(this).text().length) {
$(this).closest('.checklist-item').parent().remove();
}
});
}
});

最佳答案

正如其他人提到的,您有效地引发了递归调用。一个简单的解决方法是添加一个哨兵变量来阻止它递归:

var busy = false;
$(document).on('keypress focusout', '.checklist-item-input', function (e) {
if (!busy && e.which == 13 || e.type == 'focusout') {
busy = true;
$('.checklist-item').removeClass('edit');
$(this).siblings('.checklist-item-detail').text($(this).val());
$(this).blur();
$('.checklist-item-detail').each(function () {
if (!$(this).text().length) {
$(this).closest('.checklist-item').parent().remove();
}
});
busy = false;
}
});

关于javascript - jquery on() 方法超出最大调用堆栈大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40658712/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com