JQuery 3.4.1 无法读取未定义的 属性 'value'

JQuery 3.4.1 Cannot read property 'value' of undefined

升级 jQuery 3.4.0 到 3.4.1 后,在 blur()focus() 输入事件上,我收到 Cannot read property 'value' of undefined 错误。

that.container.on('click', '.binary_field', function(){
    $("input:focus").blur();
}

我认为这可能是 jquery 源代码发生这种变化的原因:https://github.com/jquery/jquery/commit/24d71ac70406f522fc1b09bf7c4025251ec3aee6?diff=unified#diff-031bb62d959e7e4949d1847c82507f33L579-R583

你的代码看起来不错,你的情况有一个解决方法,删除这一行的 jquery。

你可以替换

$("input:focus").blur()

来自

document.activeElement && document.activeElement.blur() 
// Test if there is a focused element, if yes remove the focus

或(使用 jQuery 和 VanillaJs)

$(document.activeElement)[0].blur()
// or
$("input:focus")[0].blur()

这是相同的行为

这是 jQuery 3.4.1 中的已知问题:

https://github.com/jquery/jquery/issues/4417

使用 JavaScript .blur() 而不是 jQuery 方法。