JavaScript compatibility with IE and Firefox

Source: Internet
Author: User
Tags definition eval

1.document.formname.item ("ItemName") problem

Note: Under IE, you can use Document.formName.item ("ItemName") or document.formname.elements["elementname"]; Firefox, you can only use the document.formname.elements["ElementName"].

Workaround: Unify the use of document.formname.elements["ElementName"]. TEXT1:

document.formName.item("itemName")    
document.formName.elements["elementName"]

-------------------------------------------------

2. Collection Class object problem

Note: IE, you can use () or [] get the Collection class object; Firefox, you can only use [] to get collection class objects.

WORKAROUND: Use [] to get collection class objects uniformly.

TEXT2:

document.forms("formName") 
document.forms["formName"] 

TEXT3:

document.getElementsByName("inputName")(0) 
document.getElementsByName("inputName")[0]

-------------------------------------------------

3. Custom attribute Issues

Note: Under IE, you can get the custom attribute by using the method of obtaining the General property, or you can use GetAttribute () to get the definition attribute. Firefox, you can only use getattribute () to get the definition attribute.

Workaround: The unification is obtained from the defined attribute through GetAttribute ().

TEXT4:

Get the value of a custom property directly

A value derived from a defined property by GetAttribute ()

-------------------------------------------------

4.eval ("idname") problem

Note: Under IE, you can use either eval ("Idname") or getElementById ("Idname") to obtain an HTML object with an ID of idname; Firefox can only use getElementById ("Idname") to get an HTML object with an ID of idname.

Workaround: Unify the getElementById ("Idname") to get the HTML object with the ID idname.

Text5:
eval("idName")          
document.getElementById("itemId")

-------------------------------------------------

Related Article

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.