Home >Web Front-end >HTML Tutorial >The difference between the ID and Name attributes of HTML elements_HTML/Xhtml_Web page production
Today I am a little confused about . Adding # means an anchor, followed by 13, it will jump to the 13 position of this page, and this 13 is the Name attribute. value. Why isn't
an ID value? ? ? So I checked the difference between ID and Name, and recorded
the most classical answer: ID is like a person’s ID number, and Name is like his name. ID is obviously unique, and Name can be repeated.
Obviously, the answer to ID and Name is too general. Of course, that explanation is completely correct for ID, which is the Identity of the HTML element on the client side. Name is actually much more complicated, because Name has many uses, so it cannot be completely replaced by ID, thus canceling it. Specific uses are:
Use 1: As a server-side indicator of HTML elements that can interact with the server, such as input, select, textarea, and button. We can get the value submitted by the element through Request.Params based on its Name on the server side.
Use 2: HTML element Input type='radio' grouping, we know that the radio button control is in the same grouping class, the check operation is mutex, only one radio can be selected at the same time, this grouping is based on the same Name attribute realized.
Use 3: Establish an anchor point in the page. We know that link is to obtain a page hyperlink. If you do not use the href attribute, use Name instead, such as: < ;a name="PageBottom">, we get a page anchor.
Use 4: Identity as an object, such as Applet, Object, Embed and other elements. For example, in an Applet object instance, we will use its Name to refer to the object.
Purpose 5: When associating between IMG elements and MAP elements, if you want to define the hotspot area of IMG, you need to use its attribute usemap, so usemap="#name" (Name of the associated MAP
element ).
Use 6: Attributes of certain specific elements, such as attribute, meta and param. For example, define parameters for Object or < META NAME = "Author" CONTENT = "Dave Raggett"> in Meta.
Obviously these uses cannot be simply replaced by ID, so the difference between ID and Name of HTML elements is not the difference between ID number and name. They have different functions
thing.
We can analyze the subtle differences through a piece of code: