Home >Web Front-end >JS Tutorial >A brief analysis of the different performances of Javascript in IE and FireFox_javascript skills
1.document.formName.item("itemName") Problem
Description: Under IE, you can use document.formName.item("itemName") or document.formName.elements["elementName"]; under Firefox, you can only use Use document.formName.elements["elementName"].
Solution: Use document.formName.elements["elementName"] uniformly.
2. Collection class object problem
Explanation: Under IE, it can be used () or [] to obtain collection objects; under Firefox, you can only use [] to obtain collection objects.
Solution: Use [] uniformly to obtain collection objects.
3. Custom attribute issues
Note: Under IE, you can use the method of getting regular attributes to get custom attributes, or you can use getAttribute() to get custom attributes; under Firefox, you can only use getAttribute() to get custom attributes.
Solution: Unification Get custom attributes through getAttribute().
4.eval("idName") problem
Explanation: Under IE, you can use eval("idName") or getElementById("idName") to get the id as idName HTML object; under Firefox, you can only use getElementById("idName") to obtain the HTML object with the id idName.
Solution: Use getElementById("idName") uniformly to obtain the HTML object with the id idName.
5. The problem that the variable name is the same as the ID of an HTML object
Note: Under IE, the ID of the HTML object can be used directly as the variable name of the subordinate object of the document; it cannot be used under Firefox. Under Firefox, the ID of the HTML object can be used as the same as the HTML object ID. variable name; this is not possible under IE.
Solution: Use document.getElementById("idName") instead of document.idName. It is best not to use variable names with the same HTML object ID to reduce errors; always add var when declaring variables to avoid ambiguity.
7.Input.type attribute problem
Explanation: The input.type attribute under IE is read-only; but under Firefox, the input.type attribute is read-write.
9.event.x and event.y problem
Note: Under IE, the even object has x, y attributes, but no pageX, pageY attributes; under Firefox, the even object has pageX, pageY attributes, but no x, y attributes.
Solution: Use mX(mX = event.x ? event.x : event.pageX;) to replace event.x under IE or event.pageX under Firefox.
10.event.srcElement problem
Explanation: Under IE, the event object has srcElement attribute, but no target attribute; under Firefox, the event object has a target attribute, but no srcElement attribute.
Solution: use obj (obj = event.srcElement ? event.srcElement : event.target;) instead under IE event.srcElement or event.target under Firefox.
13.Frame problem
Take the following frame as an example:
(1) Access the frame object:
IE: Use window.frameId or window.frameName to access this frame object.
Firefox: You can only use window.frameName to access this frame object .
In addition, you can use window.document.getElementById("frameId") in both IE and Firefox to access this frame object.
(2) Switch frame content:
Can be used in both IE and Firefox Use window.document.getElementById("testFrame").src = "xxx.html" or window.frameName.location = "xxx.html" to switch the content of the frame.
If you need to pass the parameters in the frame back to the parent Window, you can use parent in frme to access the parent window. For example: parent.document.form1.filename.value="Aqing";
14.body problem
Firefox’s body exists before the body tag is fully read by the browser; while IE’s body must be The body tag does not exist until it is completely read by the browser.
For example:
Firefox: