Home > Web Front-end > HTML Tutorial > What is the specific difference between the id and name attributes in input? (example)

What is the specific difference between the id and name attributes in input? (example)

藏色散人
Release: 2018-08-13 13:56:34
Original
5450 people have browsed it

This article mainly introduces to you the difference between the name attribute and the id attribute in the input tag in HTML. I hope it will be helpful to some confused newbies. Here I will give you a brief introduction to what the input tag is. The tag specifies an input field into which the user can enter data. According to different type attributes, input fields have multiple forms. Input fields can be text fields, checkboxes, password fields, radio buttons, input buttons, etc.

The input code usage example is as follows:

<!DOCTYPE HTML>
<html lang="en">
<head>
    <title></title>
    <meta charset="UTF-8">
    <style type="text/css">
    </style>
</head>
<body>
<form action="demo_form.asp" method="get">
    第一个名字: <input type="text" name="fname" id="f1"/><br />
    第二个名字: <input type="text" name="lname" id="f2"/><br />
    <input type="submit" value="提交" />
</form>
</body>
</html>
Copy after login

The rendering is as follows:

What is the specific difference between the id and name attributes in input? (example)

Everyone should Notice the inputname attribute and inputid attribute,

1. The name attribute of the input tag specifies the name of the input element. Used to identify form data after it is submitted to the server, or to reference form data through JavaScript on the client. Only form elements that have their name attribute set can pass their values ​​when the form is submitted.

2. The role of id in HTML is to give a unit (element, tag) a unique identifier or tag, allowing the browser to find the location of the id when analyzing and processing the web page. And it must meet the requirements of identification, such as case sensitivity, it is best not to include underscores (not compatible with CSS)

id is generally used for reference in css and js, name is used for form submission, only the name attribute is added Label elements will be submitted to the server.

The above is an introduction to the difference between the name attribute and id in input in this article. I hope it will be helpful to friends in need.

【Recommended related articles】

Input attributes in PHP

How to use? SummaryExample usage

Parsing the pattern attribute of the input box in html

Details about the input tag (type attribute) in HTML5 introduce





The above is the detailed content of What is the specific difference between the id and name attributes in input? (example). For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template