Different Javascript expressions in IE and FireFox
Source: Internet
Author: User
1.doc ument. formName. item (& quot; itemName & quot;) Problem description: You can use document. formName. item (& quot; itemName & quot;) or document. formName. elements [& quot; elementName & quot;]; Fire 1.doc ument. formName. item ("itemName ")
Description: You can use document. formName. item ("itemName") or document. formName. elements ["elementName"]; In Firefox, only document. formName. elements ["elementName"].
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: getElementById ("idName") is used to retrieve the HTML object whose id is 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.
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.
9. event. x and event. y
Note: In IE, the even object has the x and y attributes, but does not have the pageX and pageY attributes. In Firefox, the even object has the pageX and pageY attributes, but does not have the x and y attributes.
Solution: Use mX (mX = event. x? Event. x: event. pageX;) to replace event. x in IE or event. pageX in Firefox.
10. event. srcElement Problems
Note: In IE, the event object has the srcElement attribute, but does not have the target attribute. In Firefox, the event object has the target attribute, but does not have the srcElement attribute.
Solution: Use obj (obj = event. srcElement? Event. srcElement: event.targettoken used to replace event.tar get under firefox.
13. frame Problems
The following frame is used as an example:
(1) access the frame object:
IE: Use window. frameId or window. frameName to access this frame object.
Firefox: only window. frameName can be used to access this frame object.
In addition, both ieand firefoxcan access this frame object by using the upload metadata Doc ument. getElementById ("frameId.
(2) Switch frame content:
In both ieand firefox, you can use Upload upload Doc ument. getElementById ("testFrame"). src = "xxx.html" or window. frameName. location = "xxx.html" to switch frame content.
If you want to return parameters in the frame to the parent window, you can use parent in frme to access the parent window. Example: parent.doc ument. form1.filename. value = "Aqing ";
14. body Problems
The body of Firefox exists before the body tag is fully read by the browser. The body of IE must exist only after the body tag is fully read by the browser.
For example:
Firefox:
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.