自动完成HTML5文字输入? [英] Autocomplete text input for HTML5?

查看:113
本文介绍了自动完成HTML5文字输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多javascript解决方案,但是有一个HTML5的方法可以使用自动完成的文本输入? datalist元素几乎就是im后的内容,除了它允许您输入自定义值而不是限制列表中的内容。 HTML5有一个自动完成属性,它可以被指定为 code>在或 off 字段中。



下面是一个例子:

 < form action =/ form.phpautocomplete =on> 
名字:< input type =textname =first_name>< br>
姓氏:< input type =textname =last_name>< br>
电子邮件:< input type =emailname =emailautocomplete =off>
< input type =submit>
< / form>

它的工作方式是您在第一次提交的值会在后续建议您访问此页面的次数是每个字段的 keyup




  • 在决定使用此功能时的关键问题是浏览器兼容性问题之一。你最好的选择是检查多个浏览器,以确保它的工作。 caniuse.com 使支持看起来很糟糕,但我没有看到它使用它来帮助那些拥有现代浏览器的人。 / li>


其他有关 autocomplete 来自 W3Schools ,在这种情况下并不讨厌,因为它涵盖了基本知识:


  • 启用自动完成功能后,浏览器会根据用户之前输入的值自动完成
    的值。


  • 可能有自动完成的on表单,而off表示特定的输入
    字段,反之亦然。

  • autocomplete属性适用于
    以及以下类型:text,search,url,tel,email,
    password,datepickers,范围和颜色。 li>

I know there are a lot of javascript solutions, but is there an HTML5 method of having a text input with autocomplete? The datalist element is almost what im after except it allows you to enter custom values rather than limiting you to whats in the list.

解决方案

HTML5 has an autocomplete attribute which can be specified as either on or off in a field.

Here's an example:

<form action="/form.php" autocomplete="on">
  First name:<input type="text" name="first_name"><br>
  Last name: <input type="text" name="last_name"><br>
  E-mail: <input type="email" name="email" autocomplete="off">
  <input type="submit">
</form>

The way it works is that the values that you submit the first time will be suggested to you on subsequent times you visit this page on keyup of each field.

  • The key issue in deciding to use this feature is one of browser compatibility. Your best bet is checking multiple browsers to make sure it works. caniuse.com makes the support looks pretty bad, but I don't see any harm it using it to help those who have modern browers.

Other factoids about autocomplete from W3Schools, don't hate in this case as it does cover the basics:

  • When autocomplete is on, the browser automatically complete values based on values that the user has entered before.
  • It is possible to have autocomplete "on" for the form, and "off" for specific input fields, or vice versa.
  • The autocomplete attribute works with and the following types: text, search, url, tel, email, password, datepickers, range, and color.

这篇关于自动完成HTML5文字输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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