简体   繁体   English

自动完成不适用于 javascript 生成的输入字段

[英]Autocomplete doesn't work with javascript generated input fields

If you generate a login overlay with javascript (via ajax loaded content or with JS templates), browsers usually (firefox, safari) don't use autocomplete in these input fields.如果您使用 javascript(通过 ajax 加载的内容或使用 JS 模板)生成登录覆盖,浏览器通常(firefox、safari)不会在这些输入字段中使用自动完成功能。 It's really annoying, do you have any ideas how can I fix this?这真的很烦人,您有什么想法可以解决这个问题吗?

Do I need to generate a hidden form inside the original HTML and move this form into this overlay?我是否需要在原始 HTML 中生成一个隐藏表单并将此表单移动到此叠加层中?

Thanks, Andras谢谢, 安德拉斯

I was doing the same, using javascript to produce and get values from input fields.我也在做同样的事情,使用 javascript 从输入字段生成和获取值。 They would not autocomplete any text.他们不会自动完成任何文本。 I discovered that placing the input field in <form></form> allowed autocomplete to work as it should.我发现将输入字段放在<form></form>中可以让自动完成功能正常工作。 I wasn't including the form element at first because I wasn't submitting any form, just making an ajax call.起初我没有包含表单元素,因为我没有提交任何表单,只是进行了 ajax 调用。 And now that use use <form> you just gotta prevent the default form submit and make the ajax call instead.现在使用 use <form>您只需要阻止默认表单提交并改为调用 ajax 。 For example <form onsubmit="return false;">例如<form onsubmit="return false;">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM