Getelementsbyname ("test") is to extract all the elements whose name attribute is test and put them in a set and return them to you.
Getelementsbytagname ('input') is to extract all the text boxes, single choice, check, and buttons and put them in a set to return them to you.
In IE, when getelementsbyname ("test") is returned, the array of objects with ID = test is returned, and the array of objects with name = test is returned using Firefox. According to W3C standards, Firefox should be implemented correctly, but I don't know why IE is implemented as ID = test? "Obtains the object set based on the value of the name tag attribute ."
Getelementbyid in Firefox and IE are the same: Get the reference of the first object whose ID label attribute is the specified value.
In general, the single-choice button is assigned a value based on the index serial number, for example
<Input name = "txtsex" type = "radio" value = "0" class = "noborder"> male <input name = "txtsex" type = "radio" value = "1 "Class =" noborder "Checked> female
To determine whether the cheched status is not determined by the value or not in the editing status, you can use js to control which option is selected directly in the radio-button array.
Pre-Fetch the user's Gender value txtsex variable storage, and then load the form to complete the selection in Js.
<SCRIPT langauage = "JavaScript">
Document.post.txt sex [<% = txtsex %>]. Checked = true;
</SCRIPT>
If the selectelement is the plain box, configure document.post.txt sex. value = "<% = txtsex %> ";
To make ieand firefoxviewer compatible with JS objects, you should set document.post.txt sex [<% = txtsex %>]. Checked = true;
Indicates a document. getelementsbyname ("txtsex") [<% = txtsex %>]. checked = true; Because txtsex is an array element, you must use getelementsbyname instead of getelementbyname. If it is named by ID, It is getelementsbyid.
In IE, when getelementsbyname ("test") is returned, the array of objects with ID = test is returned, and the array of objects with name = test is returned using Firefox. According to W3C standards, Firefox should be implemented correctly, but I don't know why IE is implemented as ID = test? "Obtains the object set based on the value of the name tag attribute ."
Getelementbyid in Firefox and IE are the same: Get the reference of the first object whose ID label attribute is the specified value.
Among them, the most common problem in Firefox is getelementbyid,
In IE, when the original operator directly uses form's name component to obtain the following table element in the ticket form,
For example:
If (FRM. tbxuid. value = ""){
Alert ("Please refer to zookeeper ");
}
However, this method cannot be run in Firefox,
Therefore, you need to use getelementbyid to retrieve objects,
However, to use getelementbyid, the premise is that the objects in a table must have the attention content of the ID,
However, there was no ID added before...
After adding IDs to many objects, I found that there was a problem with the checkbox and radio...
Because the names of radio and checkbox are the same,
However, the ID cannot be set to the same. (subject: the ID and name of the HTML element are differentiated)
Therefore, radio and checkbox should be captured using getelementsbyname,
When getelementbyid is used, I want to say that there should be byname but getelementbyname should be deleted,
It didn't work until I read the previous article and found that it was missing a second (getelementbyname should be getelementsbyname ),
Later, I took a look at the text, areatext, and other information that I couldn't catch with getelementsbyname,
As a result, I found that I couldn't catch it, so I checked the table element one by one with a hard head...
So the above program will be changed
If (document. getelementbyid ('tbxuid'). value = ""){
Alert ("Please refer to zookeeper ");
}
It's really not easy to make all the referers accessible. Unless the content of the website is simple ....
Almost everyone who has done Web development has asked, What is the difference between the element ID and name? Why do I need a name if I have an ID? We can also get 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.
Last week, I also encountered the ID and name problems. I entered an input type = "hidden" on the page and wrote only one id = 'sliceinfo'. After the assignment, I submit it, use request. params ["sliceinfo"] does not return a value. Later, I suddenly realized that the name should be used for marking, so I added a name = 'sliceinfo' to the input, and everything was okay.
The answer to ID and name in the first section is too general. Of course, that explanation is completely correct for 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:The server-side identifier of the 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:The input type of the HTML element is 'radio'. 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 on 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 the name instead, for example: <a name = "pagebottom"> </a>.
Purpose 4: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 associating IMG elements with map elements, 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 and Param. For example, define the parameter <Param name = "appletparameter" value = "value"> for the object.
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.
Of course, the name attribute of the HTML element can also play a role of ID in the page, because in the DHTML Object Tree, we can use document. getelementsbyname is used to obtain an array of objects containing all the specified name elements on the page.
By the way, what if the IDs of n (n> 1) HTML elements on the page are the same? How can we reference them in DHTML objects? If we use the ASPX page, this situation is not easy, because the ASPNET process does not allow non-unique IDs when processing the ASPX page, this is because the page will be thrown an exception and cannot be a normal render. If we want to repeat the ID on a dynamic page, how does ie do it?
At this time, we can continue to use document. getelementbyid to get the object, except that we can only get the first object that appears in the HTML render of the objects with duplicate IDs. At this time, duplicate IDs are automatically converted into an array when being referenced. Elements with duplicate IDs exist in the array in order of render.