Solve JS differences in firefox and IE (1)

Source: Internet
Author: User

This article will focus on the differences between JS and IE and their solutions. In IE, you can use methods to obtain general attributes to obtain custom attributes, or you can use getAttribute () get custom attributes. In Firefox, you can only use getAttribute () to get custom attributes.

Differences between JS and IE and Their Solutions

1.doc ument. formName. item (itemName)

Note:

In IE, you can use document. formName. item (itemName) or document. formName. elements [elementName];

In Firefox, only document. formName. elements [elementName] can be used.
Solution: Use document. formName. elements [elementName].

2. Collection class Object Problems

Note: in IE, you can use () or [] to obtain collection class objects. In Firefox, you can only use [] to obtain collection class objects.
Solution: use [] to retrieve collection class objects.

3. Custom Attributes

Note: in IE, you can use the method to obtain general attributes to obtain custom attributes, or use getAttribute () to obtain Custom Attributes. In Firefox, you can only use getAttribute () obtain custom attributes.
Solution: getAttribute () is used to obtain custom attributes.

4. eval (idName) Problems

Note: in IE, you can use eval (idName) or getElementById (idName) to obtain the HTML object whose id is idName. In Firefox, you can only use getElementById (idName) to obtain the HTML object whose id is idName.
Solution: Use getElementById (idName) to retrieve the HTML object with id as idName.

5. The variable name is the same as the ID of an HTML object.

Note: In IE, the ID of the HTML object can be used directly as the variable name of the subordinate object of the document; in Firefox, it cannot. in Firefox, you can use the same variable name as the HTML Object ID; in IE, you cannot.
Solution: Use document. getElementById (idName) replaces document. idName. we recommend that you do not use variable names with the same HTML Object ID to reduce errors. When declaring variables, add var to avoid ambiguity.

6. const Problems

Note: In Firefox, you can use the const keyword or var keyword to define constants. in IE, you can only use the var keyword to define constants.
Solution: Use the var keyword to define constants.

7. input. type attribute Problems

Description: The input. type attribute in IE is read-only, but the input. type attribute in Firefox is read/write.


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.