浏览器自动填充和Javascript触发事件 [英] Browser Autofill and Javascript triggered events

查看:118
本文介绍了浏览器自动填充和Javascript触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的一位用户刚刚提到他们的浏览器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触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆