[英]Switch autocomplete on/off on Chrome
I want to turn on/off on autocomplete an input in Chrome, later idea is to inject custom suggestions for emails after a the next letter of an '@' char. 我想在Chrome中打开/关闭自动完成输入的功能,后来的想法是在下一个字母“ @”后插入电子邮件的自定义建议。
I get to turn autocomplete on/off but autocomplete values doesn't disappear until next key is pressed. 我可以打开/关闭自动完成功能,但是自动完成值在按下下一个键之前不会消失。
I have a demo here: jsfiddle 我在这里有一个演示: jsfiddle
const input = document.querySelector('[name=email]');
function handleChange(evt) {
const target = evt.target;
const value = evt.target.value;
const idx = evt.target.value.indexOf('@');
console.log(value.length, '-', idx);
if (evt.target.value && idx !== -1 && value.length > (idx + 1) ) {
target.autocomplete = 'off';
} else {
target.autocomplete = 'on';
}
}
input.addEventListener('keydown', handleChange);
input.addEventListener('keyup', handleChange);
Thanks! 谢谢!
To disable autocompletion in forms, you can set the autocomplete attribute to "off": 要禁用表单中的自动完成功能,可以将autocomplete属性设置为“ off”:
autocomplete="off"
You can do this either for an entire form, or for specific input elements in a form: 您可以对整个表单或表单中的特定输入元素执行此操作:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.