Some details of document.getElementById

Source: Internet
Author: User
Tags html tags
①document.getelementbyid sometimes catch name let go of ID, is said to be a bug of IE;
http://community.csdn.net/Expert/topic/4223/4223888.xml?temp=.1947443

On the page are
<input type= "hidden" id= "Hello8" name= "category_id" value= "2"/>
<select id= "category_id" >

One is Name= "category_id" one is id= "category_id"
Take the second one with document.getElementById, but the first one is taken name=category_id
In IE, getElementById is not the first catch ID but first find the same object name ...

Two form, each form has two textbox, the TextBox in the two form is the same name, but the ID is different ...
This is no problem in Firefox ... But in IE it only catches the first name information

The following code can verify this result
<HTML>
<HEAD>
<TITLE> getElementById </TITLE>
</HEAD>
<script language= "JavaScript" >
<!--
function Chkacc () {
Alert (document.getElementById ("Tbxuid1"). Value);
Alert (document.getElementById ("Tbxpwd1"). Value);
Alert (document.getElementById ("Tbxuid"). Value);
Alert (document.getElementById ("Tbxpwd"). Value);
}
-->
</SCRIPT>
<BODY>
<form method=post action= "" Name= "Frm1" >
<input type= "text" name= "Tbxuid" id= "Tbxuid1" >
<input type= "text" name= "tbxpwd" id= "TBXPWD1" >
</FORM>
<form method=post action= "" Name= "Frm2" >
<input type= "text" name= "Tbxuid" id= "Tbxuid" >
<input type= "text" name= "tbxpwd" id= "Tbxpwd" >
<input type= "button" value= "Check" name= "Btnchk" >
</FORM>
</BODY>

The use of getElementById in ②javascript
The elements in a Web page must have an id attribute in order to get them through this method, such as
<input type=text name= "content" id= "Content" >

③ There are two main ways to get HTML tags, one is through the ID value, one is through the Name property
The Name property is used primarily for input tags within form 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.