Document. getElementById details _ javascript skills

Source: Internet
Author: User
Document. getElementById details ① document. getElementById sometimes misses the name, which is said to be a BUG in IE;
Http://community.csdn.net/Expert/topic/4223/4223888.xml? Temp =. 1947443.

The page contains

Program code

One is name = "category_id" and the other is id = "category_id"Use document. getElementById to get the second one. However, the first name = category_id is obtained.In IE, getElementById does not capture the id first, but first finds the object with the same name...Two forms. Each form has two textbox. the textbox in the two forms has the same name, but the IDs are different...So there is no problem in Firefox.The following code verifies the 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> </HTML
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]



② Use getElementbyId in javascript
The elements in the web page must have the id attribute to be obtained through this method, for example


③ There are two methods to obtain html tags: ID and name.
The name attribute is mainly used for the input mark in the form.

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.