1. Use other form elements
1. Generate a list of options
The select element can be used to generate a list of options for the user to choose from. The
size attribute is used to set the number of options to be displayed to the user; the
multiple attribute allows the user to select multiple options at a time.
Example 1: Selection list
<label for="fave"> Favorite Fruit: <select name="fave" id="fave"> <option value="apples">苹果</option> <option value="organges">橘子</option> <option value="pears">梨</option> </select></label>
Example 2: Selection list, supports multiple selections at the same time
<label for="like"> Like Sport: <select name="like" id="like" size="3" multiple> <option value="football">足球</option> <option value="basketball">篮球</option> <option value="table tennis">乒乓球</option> <option value="badminton">羽毛球</option> <option value="swiming">游泳</option> </select> </label>
Example 3: Creating a structure
<label for="love"> <select name="love" id="love"> <optgroup label="前端语言"> <option value="javascript">JavaScript</option> <option value="html">Html</option> <option value="css">CSS</option> </optgroup> <optgroup label="后端语言"> <option value="java">Java</option> <option value="php">PHP</option> </optgroup> </select></label>
2. Enter multiple lines of text
# The ##textarea element generates a multi-line text box, and the user can enter multiple lines of text.Description | |
---|---|
Number of rows | |
Number of columns | |
Control the insertion of line breaks in the text when submitting the form Method: hard will insert line breaks; soft will not |
Example: use textarea element
<form action="http://localhost:8888/form/select" method="post"> <p> <label for="textarea_1"> 请输入一段文字:<textarea name="textarea_1" id="textarea_1" cols="30" rows="10" wrap="soft"></textarea> </label> </p> <p> <label for="textarea_2"> 请再次输入一段文字:<textarea name="textarea_2" id="textarea_2" cols="30" rows="10" wrap="hard"></textarea> </label> </p> <input type="submit" value="提交"></form>3. Indicates the calculation result output indicates the calculation result.
Example: Calculation results
<form action="return false;" oninput="res.value = quantity.value * price.value"> <fieldset> <legend>价格计算</legend> <input type="number" placeholder="数量" id="quantity" name="quantity"> x <input type="number" placeholder="价格" id="price" name="price"> = <output for="quantity price" name="res"></output> </fieldset></form>2. Use input validationHTML5 introduces support for input validation. Designers can tell the browser what type of data they need, and the browser will use this information to check whether the data entered by the user is valid before submitting the form.
The advantage is: users can get problem feedback immediately.
Supported elements | |
---|---|
textarea, select, input (text, search, url, telephone, email, password, date pickers, number, checkbox, radio and file) | |
input(umber, range, date, datetime, datetime-local, month, time and week) | |
input(text, search, url, telephone, email and password) |
Example: Verification
<form action="http://localhost:8888/form/validate" method="post"> <p> <label for="name"> 姓名:<input type="text" name="name" id="name" required> </label> </p> <p> <label for="email"> 邮箱:<input type="text" name="email" id="email" required pattern="\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-) [A-Za-z0-9]+)*\.[A-Za-z0-9]+"> </label> </p> <p> <label for="age"> 年龄:<input type="number" name="age" id="age" min="1" max="150"> </label> </p> <input type="submit" value="提交"></form>
Note: Pattern verification email and URL, do not enter It will not trigger verification when the content is included, so it needs to be used in conjunction with required!
Disable input validation: You can set the novalidate attribute of the form element, or you can set the formnovalidate attribute of the button or input element used to submit the form.
The above is the detailed content of HTML5-Detailed explanation of form input validation (picture and text). For more information, please follow other related articles on the PHP Chinese website!

HTML5 brings five key improvements: 1. Semantic tags improve code clarity and SEO effects; 2. Multimedia support simplifies video and audio embedding; 3. Form enhancement simplifies verification; 4. Offline and local storage improves user experience; 5. Canvas and graphics functions enhance the visualization of web pages.

The core features of HTML5 include semantic tags, multimedia support, offline storage and local storage, and form enhancement. 1. Semantic tags such as, etc. to improve code readability and SEO effect. 2. Simplify multimedia embedding with labels. 3. Offline storage and local storage such as ApplicationCache and LocalStorage support network-free operation and data storage. 4. Form enhancement introduces new input types and verification properties to simplify processing and verification.

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.

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.

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.

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 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.

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.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
