The
input element can generate a simple text box for users to enter data. The disadvantage is that the user can enter any value, and the type type can be configured to obtain additional attributes. The type attribute has 23 different values, while the input element has a total of 30 attributes, many of which can only be used with specific type attribute values.
1. Use the input element to enter text
The input element whose type attribute is set to text is displayed as a single-line text box in the browser.
1. Set the element size
maxlength attribute sets the maximum number of characters that the user can input;
size attribute sets the number of characters that the text box can display.
<label for="username"></label> <input type="text" name="username" id="username" maxlength="10" size="20">
2. Set the initial value and placeholder prompt
The value attribute sets the default value;
The placeholder attribute sets a prompt text to inform the user what type of data to enter.
<label for="address"></label> <input type="text" name="address" id="address" value="北京市"> <label for="tel"></label> <input type="text" name="telephone" placeholder="请输入电话号码">
3. Using data list
You can set the list attribute of the input element to the id attribute value of a datalist element, so that when the user enters data in the text box, he only needs to start from the latter element. Just choose from the batch of options provided.
<input type="text" name="city" list="cityList"> <datalist id="cityList"> <option value="BeiJing" label="北京市"></option> <option value="QingDao">青岛市</option> <option value="YanTai"></option> </datalist>
The picture is displayed under HTML5-detailed code examples for customizing input elements
The picture is displayed under HTML5-detailed code examples for customizing input elements
Note: The performance will be different under different browsers
(1) Each option element in the datalist element represents a value for the user to select, and its value attribute value is when the option represented by the element is selected. The data value used by the input element;
(2) Description information, which can be set through the label attribute or as the content of the option element.
4. Generate a read-only or disabled text box
Both the readonly and disabled attributes can be used to generate a text box that cannot be edited by the user, and the resulting appearance will be different.
<input type="text" name="readonly" value="readonly" readonly> <input type="text" name="disabled" value="disabled" disabled>
Note: The data of the input element with the disabled attribute set cannot be submitted to the server; the data of the input element with the readonly attribute can be submitted to Server;
Recommendation: The readonly attribute needs to be used with caution (no visual signal informs the user that editing is prohibited, the user cannot input, and the user is confused), and the use of hidden type input elements should be considered;
2. Use input elements to check input data
1. Use input elements to obtain numerical values
The input box generated by an input element whose type attribute is set to number is only allowed to accept numerical values.
min sets the minimum acceptable value;
max sets the maximum acceptable value;
step specifies the step size for adjusting the value up and down.
<fieldset> <legend>number</legend> <label for="score">分数:</label> <input type="number" name="score" id="score" min="60" max="100" step="5"></fieldset>
2. Use the input element to obtain a value within a specified range
The range input element can specify a value range in advance for the user to choose.
<fieldset> <legend>range</legend> <label for="price">价格:</label> <span>1</span> <input type="range" name="price" id="price" min="0" max="100" step="5"> <span>100</span></fieldset>
3. Use the input element to obtain Boolean input
The checkbox input will generate a check box for the user to select yes or no.
<fieldset> <legend>checkbox</legend> <input type="checkbox" name="agree" id="agree"> <label for="agree">同意条款</label></fieldset>
Note: When submitting a form, only the data value of the checked check box will be sent to the server (if the data item of the checkbox input element does not exist in the submitted item , indicating that the user has not checked).
4. Use the input element to generate a set of fixed options
The radio input element is used to generate a set of radio buttons for users to choose from a set of fixed options. It is suitable for situations where there is not much valid data available. To generate a mutually exclusive set of options, simply set the name attribute of all related input elements to the same value.
<fieldset> <legend>选出你最喜欢的水果:</legend> <label for="oranges"> <input type="radio" value="oranges" id="oranges" name="fave"> Oranges </label> <label for="apples"> <input type="radio" value="apples" id="apples" name="fave" checked> Apples </label></fieldset>
5. Use the input element to obtain a string with a specified format
The input elements whose type attribute is set to email, tel, and url can accept valid email addresses, respectively. Phone number and URL.
<fieldset> <legend>规定格式的字符串</legend> <p> <label for="email"> 邮箱:<input type="email" name="email" id="email"> </label> </p> <p> <label for="password"> 密码:<input type="password" name="password" id="password"> </label> </p> <p> <label for="tel"> 电话:<input type="tel" name="tel" id="tel"> </label> </p> <p> <label for="url"> URL:<input type="text" name="url" id="url"> </label> </p></fieldset>
Note: The above type of input elements will only detect the data entered by the user when submitting the form, and the checking effects vary.
6. Use input elements to get time and dateExplanation | Example (under HTML5-detailed code examples for customizing input elements ) | |
---|---|---|
Get the universal time date and time, including time zone information | According to the filling situation | |
Get the local date and time, excluding time zone information | According to the filling situation | |
Get the local date | 2016-08-12 | |
Get the year and month information | 2016-08 | |
Get time | 13:00 | |
Get Current week | 2016-W32 |
属性 | 说明 |
---|---|
accept | 指定接受的MIME类型 |
multipe | 设置这个属性的input元素可一次上传多个文件 |
<form action="http://localhost:8888/form/uploadFile" method="post" enctype="multipart/form-data"> <label for="filedata">请选择文件:</label> <input type="file" name="filedata" id="filedata"> <button type="submit">提交</button></form>
注意:表单编码类型为multipart/form-data的时候才能上传文件。
The above is the detailed content of HTML5-detailed code examples for customizing input elements. For more information, please follow other related articles on the PHP Chinese website!

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.

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.

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.

HTML5 is a key technology for building modern web pages, providing many new elements and features. 1. HTML5 introduces semantic elements such as, , etc., which enhances web page structure and SEO. 2. Support multimedia elements and embed media without plug-ins. 3. Forms enhance new input types and verification properties, simplifying the verification process. 4. Offer offline and local storage functions to improve web page performance and user experience.


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

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

Atom editor mac version download
The most popular open source editor

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.

Zend Studio 13.0.1
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools
