使文本输入字段记住以前输入的数据 [英] Make text input fields remember previously entered data

查看:86
本文介绍了使文本输入字段记住以前输入的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文字输入似乎不记得之前输入的值。例如,许多我甚至没有账户的网站,例如,之前输入过我的电子邮件地址(以客人的身份购买火车票)给我一种带有我用过的电子邮件地址的下拉列表以往。然而我的表单并没有这样做。它要求我每次都完整地输入。似乎与这个问题相反。



我有简单的输入,例如< input type =textid =firstNameplaceholder =First name/>



并且它们使用简单的jquery ajax post提交。像。然而,在这个例子中,ajax并不适用于jsbin,我只是展示它来展示我的基本结构。有没有一个jQuery插件?任何方式我都可以控制这种看似浏览器驱动的行为。在大多数浏览器中,您可以让浏览器显示以前在输入字段中输入的值,方法是给输入名称。例如:

 < input type =textid =firstNameplaceholder =First namename =firstName > 

如果该字段没有名称属性,浏览器将不会显示建议。



同时检查javascript是否阻止提交时的默认操作。


My text inputs seem not to remember values that have been typed before. For example, many websites that I don't even have an account on, but have, for example entered my email address before (buying a train ticket as a "guest") give me a sort of dropdown with email addresses I've used in the past. Yet my form does not do this. It obliges me to type it out completely every time. Seems to be the opposite of this question..

I have simple inputs like <input type="text" id="firstName" placeholder="First name" />

And they are submitted with simple jquery ajax post. Something like this. However the ajax isn't working on jsbin on that example, I just show it to demonstrate my basic structure. Is there a jquery plugin for this? Any way I can control this seemingly browser-driven behavior. Thanks.

解决方案

In most browsers, you can make your browser display values previously entered in input fields by giving a name to the input. For example:

<input type="text" id="firstName" placeholder="First name" name="firstName" >

If the field has no name attribute, the browser won't show suggestions.

Also check if javascript prevents the default action on submit.

这篇关于使文本输入字段记住以前输入的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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