[英]How do I trigger on blur and run through all inputs in a row?
I have a problem with a trigger in jQuery. 我在jQuery中遇到触发器问题。 It triggers too many times.
它触发太多次。
I have a table with 11 inputs per row. 我有一个表,每行11个输入。 I need the script to trigger a blur once per input in the row I left, when I change row.
当我更改行时,我需要脚本在我离开的行中的每个输入上触发一次模糊。
My main event handlers looks like this: 我的主事件处理程序如下所示:
$('#auto_insert').on('blur', 'input.autoupdate', function (event) {
event.stopPropagation();
event.preventDefault();
rid = $(this).closest('tr').attr('id');
row_validate(rid);
});
$('#auto_insert').on('focus', 'input.autoupdate', function (e) {
e.stopPropagation();
e.preventDefault();
newid = $(this).closest('tr').attr('id');
check();
});
The function row_validate
is used for validating and needs to run through all the inputs in a row: 函数
row_validate
用于验证,并且需要遍历一行中的所有输入:
function row_validate(rid) {
$('#auto_insert #' + rid + ' td input.autoupdate').each(function () {
$(this).trigger('blur');
});
}
Any suggestions as to why it won't work? 关于它为什么行不通的任何建议?
It mostly does what it should, but it keeps looping and I'm unsure why. 它主要做应做的事情,但它不断循环播放,我不确定为什么。
New info: 新信息:
It seems like its a massibe bubbeling effect that makes my validation run out of control. 似乎它的按摩效果使我的验证失去了控制。 is there a way to prevent it bubbling past my tr?
有没有办法防止它冒泡过我的tr?
Your problem is that the handler for the blur
event calls row_validate()
which triggers a blur
event for every cell -> endless loop. 您的问题是,
blur
事件的处理程序调用row_validate()
,该触发器为每个单元格触发一个blur
事件->无限循环。
What you need to do is to move validation into a new function which only validates. 您需要做的是将验证移到仅验证的新功能中。 Then call this new function from the blur handler (single cell change) and from the
row_validate()
function (row change). 然后从模糊处理程序(单个单元格更改)和
row_validate()
函数(行更改)中调用此新函数。
The validate function itself must not trigger any events!! validate函数本身不能触发任何事件!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.