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.