search
HomeWeb Front-endH5 TutorialDetailed explanation of HTML5 new form attributes

New formAttributes

The most complete form attributes can be obtained by checking the w3cschool-h5 form attributes. Here we only explain the common attributes

autocomplete(Autocomplete)

can record the user’s input and give prompts. This is the role of autocomplete

  • ##Value:

    • on: turn on

    • off: turn off

  • Applicability:

    • Generally used in

      input tags

  • Sample code:

  • <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <form action="" >
        <input type="text" autocomplete="on" name="userName">
        <input type="submit">
    </form>
    </body>
    </html>
  • Usage Note:

    • The tag needs to add the

      name attribute

    • The prompt will only appear after submitting once

autofocus(get focus)

When a page has many elements for input, the user needs to use the mouse to click on the elements for input. In order to improve the user experience , we can specify the default selected elements in the page through the

autofocus attribute

  • Usage method:

    • Which

      form element is needed To get the focus, just add the attribute

    • No need to assign a value, just add the attribute Please see the sample code

  • Sample code:

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Title</title>
    </head>
    <body>
    <form action="" >
      姓名:<input type="text"  name="userName">
      <br/>
      年龄<input type="number" name="telNum" autofocus>
      <input type="submit">
    </form>
    </body>
    </html>

  • Usage Note:

    • Before this attribute was available, you could use

      JavaScript<a href="http://www.php.cn/wiki/48.html" target="_blank"></a> to specify the element

    • If multiple elements in the page have this attribute set, the last one will get focus

form (form association)

When we want to When you want to submit data, you need to put the

form element in the corresponding form tag. The appearance of this attribute makes the placement of the form element no longer affected by Constraint

  • Usage method:

    • Want a certain

      The element outside the form is connected to the form. You only need to add the attribute form="form id" to the element and set it to the form id## you want to establish a relationship with. #That’s it

    Example code
    • Let the form enter your favorite
    • input

      tags and id is userForm form to establish contact

    • <!DOCTYPE html>
      <html lang="en">
      <head>
          <meta charset="UTF-8">
          <title>Title</title>
      </head>
      <body>
      <form action="" id="userForm" >
          姓名:<input type="text"  name="userName">
          <br/>
          年龄:<input type="number" name="telNum" autofocus>
          <br/>
          <input type="submit">
      </form>
      
      <br/>
      爱好:<input type="text" name="habbit" form="userForm">
      </body>
      </html>
  • Usage Note:

    • Although this attribute can make the placement of elements no longer a restriction, it is still recommended when coding to place elements in the corresponding form. In addition to compatibility issues, it is also to improve the readability and readability of the code. Maintainability
    multiple(multiple selection)

If you want to select multiple in a certain
input

tag value, you can use this attribute

  • Applicable situations:

    • This attribute can be used in type is
    • file<a href="http://www.php.cn/wiki/1313.html" target="_blank"></a>

    #Sample code
    • select When working with multiple files, you need to hold down the
    • ctrl

      button

      <input>

    • ##placeholder(placeholder prompt)

Some prompt information is displayed by default in the input element, which disappears automatically after the user inputs. We need to use

JavaScript
to achieve this effect until the

placeholder attribute appears

    Usage:
  • Just assign the content you want to prompt to this property directly
    Applicable situations:
  • If you want to implement prompts without using
      JavaScript
    • Function

    Sample code:
  • ##placeholder.pngDetailed explanation of HTML5 new form attributes

    • 显示效果如下

<input type="text"placeholder="输入用户名">

新的表单元素

除了在input标签中增加了一些新的type属性以外,H5也推出了一些新的表单元素,由于浏览器的兼容问题,使用频率并不广,了解即可 w3cSchool_新表单元素

datalist

该元素规定了输入区域的选项列表,可以让用户有一些选项

  • 测试代码:

    • 注:测试代码只是body内部的代码

网址:<input type="url" list="url_list" name="link"/>
<datalist id="url_list">
    <option label="W3School" value="http://www.W3School.com.cn"/>
    <option label="Google" value="http://www.google.com"/>
    <option label="Microsoft" value="http://www.microsoft.com"/>
</datalist>

电话: <input type="tel" list="tel_list">
<datalist id="tel_list">
    <option value="186xxx" label="移动">移动</option>
    <option value="187xxx" label="联通">联通</option>
    <option value="135xxx" label="天翼">天翼</option>
</datalist>
  • datalist:

    • id:id属性,想要使用该datalist的元素需要通过list=id的方式来指定

  • option:

    • value:指定具体的值

    • label:提示信息

  • 注意:

    • 如果input的type为url,option中对应的value需要使用http://开始

keygen

keygen 元素是密钥对生成器(key-pair generator)。当提交表单时,会生成两个键,一个是私钥,一个公钥。
私钥(private key)存储于客户端,公钥(public key)则被发送到服务器。公钥可用于之后验证用户的客户端证书(client certificate),即实现非对称加密
目前,浏览器对此元素的糟糕的支持度不足以使其成为一种有用的安全标准。

  • 使用频率:

output

属于新的语义标签:用来放置输出的内容,但是不能自动的计算结果,依旧需要通过js的方式来动态修改结果,只是相比于其他的标签,语义性更强

  • 使用频率:

【相关推荐】

1. 免费h5在线视频教程

2. HTML5 完整版手册

3. php.cn原创html5视频教程

The above is the detailed content of Detailed explanation of HTML5 new form attributes. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
H5 Code Examples: Practical Applications and TutorialsH5 Code Examples: Practical Applications and TutorialsApr 25, 2025 am 12:10 AM

H5 provides a variety of new features and functions, greatly enhancing the capabilities of front-end development. 1. Multimedia support: embed media through and elements, no plug-ins are required. 2. Canvas: Use elements to dynamically render 2D graphics and animations. 3. Local storage: implement persistent data storage through localStorage and sessionStorage to improve user experience.

The Connection Between H5 and HTML5: Similarities and DifferencesThe Connection Between H5 and HTML5: Similarities and DifferencesApr 24, 2025 am 12:01 AM

H5 and HTML5 are different concepts: HTML5 is a version of HTML, containing new elements and APIs; H5 is a mobile application development framework based on HTML5. HTML5 parses and renders code through the browser, while H5 applications need to run containers and interact with native code through JavaScript.

The Building Blocks of H5 Code: Key Elements and Their PurposeThe Building Blocks of H5 Code: Key Elements and Their PurposeApr 23, 2025 am 12:09 AM

Key elements of HTML5 include,,,,,, etc., which are used to build modern web pages. 1. Define the head content, 2. Used to navigate the link, 3. Represent the content of independent articles, 4. Organize the page content, 5. Display the sidebar content, 6. Define the footer, these elements enhance the structure and functionality of the web page.

HTML5 and H5: Understanding the Common UsageHTML5 and H5: Understanding the Common UsageApr 22, 2025 am 12:01 AM

There is no difference between HTML5 and H5, which is the abbreviation of HTML5. 1.HTML5 is the fifth version of HTML, which enhances the multimedia and interactive functions of web pages. 2.H5 is often used to refer to HTML5-based mobile web pages or applications, and is suitable for various mobile devices.

HTML5: The Building Blocks of the Modern Web (H5)HTML5: The Building Blocks of the Modern Web (H5)Apr 21, 2025 am 12:05 AM

HTML5 is the latest version of the Hypertext Markup Language, standardized by W3C. HTML5 introduces new semantic tags, multimedia support and form enhancements, improving web structure, user experience and SEO effects. HTML5 introduces new semantic tags, such as, ,, etc., to make the web page structure clearer and the SEO effect better. HTML5 supports multimedia elements and no third-party plug-ins are required, improving user experience and loading speed. HTML5 enhances form functions and introduces new input types such as, etc., which improves user experience and form verification efficiency.

H5 Code: Writing Clean and Efficient HTML5H5 Code: Writing Clean and Efficient HTML5Apr 20, 2025 am 12:06 AM

How to write clean and efficient HTML5 code? The answer is to avoid common mistakes by semanticizing tags, structured code, performance optimization and avoiding common mistakes. 1. Use semantic tags such as, etc. to improve code readability and SEO effect. 2. Keep the code structured and readable, using appropriate indentation and comments. 3. Optimize performance by reducing unnecessary tags, using CDN and compressing code. 4. Avoid common mistakes, such as the tag not closed, and ensure the validity of the code.

H5: How It Enhances User Experience on the WebH5: How It Enhances User Experience on the WebApr 19, 2025 am 12:08 AM

H5 improves web user experience with multimedia support, offline storage and performance optimization. 1) Multimedia support: H5 and elements simplify development and improve user experience. 2) Offline storage: WebStorage and IndexedDB allow offline use to improve the experience. 3) Performance optimization: WebWorkers and elements optimize performance to reduce bandwidth consumption.

Deconstructing H5 Code: Tags, Elements, and AttributesDeconstructing H5 Code: Tags, Elements, and AttributesApr 18, 2025 am 12:06 AM

HTML5 code consists of tags, elements and attributes: 1. The tag defines the content type and is surrounded by angle brackets, such as. 2. Elements are composed of start tags, contents and end tags, such as contents. 3. Attributes define key-value pairs in the start tag, enhance functions, such as. These are the basic units for building web structure.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft