In-depth learning HTML: Humble ID and Name attributes of distinction
Related Tags:
It can be said that almost every development of the Web done all asked, in the end elements of the id and Name What is the difference between Afghanistan? Why ID will have a Name?! And Similarly, we can also be the most classical answer to the question: ID is like a person's identity card number, and Name is like his name, is the only ID, and can Name repetitive.
Last week I also encountered the problem of ID and Name, type in a page input type = "hidden", which wrote an ID = 'SliceInfo', assigned submit, in the Background with Request.Params [ "SliceInfo "] but also how not to value. Later came because of the marking by Name, so the input of the Riga Name = 'SliceInfo' on the all ok.
In the first paragraph of the ID and Name answers that were too general, of course explain that the ID is completely right, and it is the Client-HTML elements Identity. Name and actually more complicated, because there are different types of Name purposes, so it can not be fully replaced by the ID, which will be its Quxiaodiao. Specific uses:
Use 1: As with interactive data server html Element marking the end of the server, such as input, select, textarea, and the button, etc.. We can Name Server under its Request.Params made by the value of the element.
Uses 2: HTML element Input type = 'radio' division, we know that the radio button controls in the same sub-category, check operation is mutex, selected the same time only a radio, this group is under the same Name attribute to them.
Uses 3: A page for the anchor, we know that <a href = "URL"> link </ a> is access to a page hyperlink, if not href attribute, instead Name, such as: <a name = "PageBottom"> </ a>, we received a page anchor.
Uses 4: As Object Identity, such as Applet, Object, Embed and other elements. For example, in Applet instance, we will use to invoke the Name of the object.
Uses 5: IMG element in the MAP and the linkages between elements, if it is used to define a hot IMG region, need to use their property usemap, usemap = "# name" (MAP was linked to elements of Name).
Uses 6: certain elements of the attributes, such as attribute, meta and param. Object definition of parameters such as <PARAM NAME = "appletParameter" VALUE = "value"> or in Meta <META NAME = "Author" CONTENT = "Dave Raggett">.
Clearly these purposes is not simple to use ID to replace the swap, so HTML elements of the ID and Name it is not the identity card number and other names such differences, which are more of this is the role of different things.
Name of course, the HTML element attributes in the pages can also play a role so that the ID, because the DHTML object tree, we can use to obtain a document.getElementsByName page contains all the elements specified Name Object array. Name attribute there is a problem, when we can create dynamic Name attribute contains the element, not simply the use of assignment element.name = "..." add to its Name, but must be in the creation of Element, the use of document.createElement ( '<element name = "myName"> </ element>') to add elements Name attribute. What does this mean ah? Look at the following example to understand.
<script Language="JavaScript">
Var input = document.createElement ( 'INPUT');
Input.id = 'myId';
Input.name = 'myName';
Alert (input.outerHTML);
</ Script>
The results show that the information box: <INPUT id = myId>.
<script Language="JavaScript">
Var input = document.createElement ( '<INPUT name="myName">');
Input.id = 'myId';
Alert (input.outerHTML);
</ Script>
The results show that the information box: <INPUT id = myName myId name =>.
Initialization Name attributes of the design is not IE flaw, because MSDN, said the need to do so, but this design principle? I do not have too much to understand.
Here again the way, if pages are n (n> 1)-HTML elements of the ID are the same how do? In the DHTML object in how they use? If we use ASPX pages, the situation is not so high, because aspnet process in dealing with the aspx page simply does not allow any non-ID only, which is abnormal pages will be thrown out can not be normal render. If not dynamic pages, we insist on ID to repeat that IE how engaging? This time, we can still continue to use document.getElementById acquisition target, but we can only obtain ID duplicate those in the HTML Render object when the object first. And then repeat the ID will be invoked automatically become an array, ID Render repetitive elements of the order exists in the array.
- Learning CSS
- Css learning some experience
- Css learning in the Filter
- CSS layout learning experience
- Learning css 3
- CSS learning
- Css learning pace
- Css learning Notes - yyy431706 (of Portland)
- CSS layout of the learning some ideas
- Css learning my feelings!
- Learning css 4
- Five learning css
- CSS learning from entry to the master
- CSS learning "text attributes"
- Css learning Notes
- CSS cascading style of learning [2]
- Css learning (1)
- CSS cascading style of learning [1]
- Css learning Notes (1)
- CSS learning should pay attention to learning method




