Basic html knowledge completion

Source: Internet
Author: User

Differences between id and name

The attribute of ID is the highest level. The name level in form is relatively low. If I want to get a value, use these two methods to write it as follows:
This is the name statement.

 window.document.form.name.value  

 

And ID, you only need to use
ID. value

You can capture the value directly. Because it is higher than the window level, you only need to use

 

Both ID and Name can be used to identify a tag. Javascript has two methods, getElementById and getElementByName, respectively, to locate the Dom node.
The differences are as follows:
1. We know that when a Web page is submitted for Post, it is submitted in Form (Form field, A Form contains several Form objects (for example, <input type = "text" name = "UserName" value = "Enter name"/> ), the same page can contain multiple forms (Asp.net, which only supports one Form and must be named Form1). After the Form table is submitted to the server, the value of the form field can be obtained directly through the Name attribute, but the value of the form object cannot be obtained directly through the ID.
2. The same Form cannot have multiple HTML tags with the same name attribute. However, if a webpage has multiple forms, different forms can have tags with the same Name attribute. The ID is global. In an HTML document, multiple nodes cannot use the same ID, no matter which Form it is in.
3. When creating a CSS style, you can create an ID style table (prefix with #) so that the style with this ID can be applied directly, but the Name style table cannot be created.
4. We recommend that you use ID to identify a node during webpage editing, instead of using Name (unless required for Post submission ), we recommend that you use the getElementById method when using Javascript For Dom node locating. Because only the ID can uniquely identify a node, multiple nodes with the same Name attribute may exist in the same webpage, they are in different forms.

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.