问题描述
我们的一位用户刚刚提到他们的浏览器Autofill不会导致JS onChange事件触发;这导致用户注册我们的问题。
One of our users just brought up the fact that their browsers Autofill doesn't cause JS onChange events to fire; this causes a problem with user registration for us.
这是设计的吗?有没有办法解决它?
Is this by design? Is there a way to work around it?
推荐答案
我偶尔使用的一个解决方案是检查字段的值是否有用/ input / select与defaultValue不同。 defaultValue将是最初在标记中的值,value是当前值,也就是选择或输入的值。即使表格是自动填充的,这可能会有所不同。
One solution I have been using occasionally is to check whether the value of the field/input/select differs from it's defaultValue. defaultValue would be the value that was originally in the markup, and value is the current value aka selected or entered value. This would probably differ even though the form was autopopulated.
如果您想完全关闭自动填充功能,最好在直接连接到逻辑的字段上添加autocomplete =off。
If you want to turn off autofill altogether, it might be wise to add autocomplete="off" on fields that are directly connected to your logic.
这篇关于浏览器自动填充和Javascript触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!