The difference between the ID and Name attributes of HTML elements. The idname attribute of html elements

Source: Internet
Author: User

The difference between the ID and Name attributes of HTML elements. The idname attribute of html elements

Differences between the ID and Name attributes of HTML elements
Today, I was suddenly excited. I want to learn more about the specific differences between the two attributes.
The most classical answer: ID is like a person's ID card number, and Name is like his Name. ID is obviously unique, and Name can be repeated. Obviously, the answer to this ID and Name is too general. Of course, that explanation is completely correct for the ID. It is the Identity of the HTML element on the Client side. Name is actually much more complex, because Name has many purposes, so it cannot be completely replaced by ID, so it is canceled. Specific uses include:
Purpose 1: ID of the server as an HTML element that can interact with the server, such as input, select, textarea, And button. On the server side, we can use Request. Params to obtain the value submitted by the element based on its Name.

Purpose 2: HTML element Input type = 'radio' group. We know that the radio button control is in the same group class. The check operation is mutex and only one radio can be selected at a time, this group is implemented based on the same Name attribute.

Purpose 3: Create an anchor in the page. We know that <a href = "URL"> link </a> is used to obtain a page hyperlink. If you do not use the href attribute, use Name instead, for example, <a name = "PageBottom"> </a>.

Purpose 4: act as the Identity of an Object, such as Applet, Object, and Embed. For example, in the Applet object instance, we will use its Name to reference this object.

Purpose 5: When the IMG and MAP elements are associated, if you want to define the IMG hotspot area, you need to use its attribute usemap, make usemap = "# name" (Name of the associated MAP element ).

Purpose 6: Attributes of certain elements, such as attribute, meta, And param. For example, define <param name = "appletParameter" VALUE = "value"> for an Object or <Meta NAME = "Author" CONTENT = "Dave Raggett"> in META.

Obviously, these functions are not simply replaced by IDS, so the ID and Name of the HTML element are not the same as the ID card number and Name, they are actually different things.

<Input name = "xx"> data is submitted. <input id = "xx"> no data is submitted.
<Input id = "xx" name = "yy"> <label for = "xx"> Label </label> The for Attribute must point to an id. Otherwise, the result is ineffective.
<Input name = "xx" type = "radio" value = "1"> <input name = "xx" type = "radio" value = "2"> <input name = "xx" type = "radio" value = "3"> A group of radio buttons must have the same name, but id does not have this function.
<Input name = "xx"> corresponding script document. getElementsByName ("xx") [0] <input id = "xx"> corresponding script document. getElementByIdx_x ("xx ")

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.