And the difference between the ID attribute name attribute tag

And the difference between the ID attribute name attribute tag

Programming for so long, fine thought for a moment, found that the problem is not clear, sweat! I read a few articles, compiled a share next!

      When it comes to the case of a friend "ID is like a person's identity card number, and Name is like his name, ID is clearly unique, and Name can be repeated," I feel very apt! [Oh it's so general, following careful to talk about! Specific] will be "ID is the Identity Client side HTML elements. In fact, the Name is much more complex, because there are many uses Name, so that it can not be completely replaced by the ID, so as to be canceled."

       For the name, there are about purposes:

(1) Use 1: Flag as HTML elements interact with the server can be a server-side data, such as input, select, textarea, button, and the like. On the server side we can get the value of the element according to its Name submitted by Request.Params.

(2) Use 2: HTML elements Input type = 'radio' group, we know the radio button controls in the same packet type, check the operation of a mutex, the same time can only select a radio, this grouping is to be based on the same property Name achieved.

(3) Use 3: Create page anchor, we know that <a href="URL"> link </a> is to get a page hyperlink, if not href attribute, in favor of Name, such as: <a name = "PageBottom"> </a>, we get a page anchor.

(4) Use 4: Identity as a target, such as Applet, Object, Embed other elements. For example, in Applet object instance, we will use its Name to refer to the object.
(5) Use 5: When the association between elements IMG and MAP elements, if the definition of the hot spot region IMG, its properties need to use the usemap, so usemap = "# name" (MAP elements are associated with the Name).
   (6) Use 6: Properties of certain elements, such as attribute, meta and param. Object definitions, for example, the parameter <PARAM NAME = "appletParameter" VALUE = "value"> or the Meta <META NAME = "Author" CONTENT = "Dave Raggett">.
    Obviously these uses are not able to simply use the ID instead of out, so the ID and Name HTML elements but do not identity card number and the name of such a distinction, this is something they are more different roles.

[Personally application is concerned, the biggest difference between feeling the place is: name generally used for request "value", but it id, used to get when using CSS style sheets]

One man says "id is a unique identifier of the control, the background server with id not name, and then the client can use id" in [.net, looks like also makes sense! ]

There this man:

1, we do know that when the page Post submission, based Form (ie, form fields) be submitted as a unit, a Form, there are a number of form objects (such as <input type = "text" name = "UserName" value = " Please enter the name "/>), the same page may be (different for multiple form Asp.net, it is only allowed to have one, and the name must Form1), after the table in the form submitted to the server, directly through the name property take the form field values, but the value can not be taken directly to the table by the form object ID.

   2, the same can not have a plurality of Form same name attribute HTML tags, but if there are multiple Form a page, then there may be different Form marked with a Name attribute. The ID is global and can not have multiple nodes with the same ID in an HTML document, regardless of what it is in the Form.

   3, when building CSS styles, you can create a style sheet ID (prefixed with a #), the style with that ID directly apply the style, the style sheet can not be established Name.

   4, it is recommended to use a node ID to identify, rather than using Name (unless it is required to submit Post) during page editing, we recommend using Javascript getElementById method when using the same conduct Dom node localization, because only ID uniquely identifies a node , while the same page in the same node may have multiple attributes Name, which are at different Form in.

 

Excerpt: https: //blog.csdn.net/tss139/article/details/80297207

Guess you like

Origin www.cnblogs.com/xingkongzhizhu/p/10951106.html