Home >
Web Front-end >
JS Tutorial >
Analysis of the difference between javascript css in IE and Firefox_javascript skills
Analysis of the difference between javascript css in IE and Firefox_javascript skills
WBOY
Release: 2016-05-16 18:55:52
Original
862 people have browsed it
1. Document.formName.item("itemName") problem Problem description: Under IE, you can use document.formName.item("itemName") or document.formName.elements ["elementName" ]; Under Firefox, only document.formName.elements["elementName"] can be used. Solution: Use document.formName.elements["elementName"] uniformly.
2. Problems with collection objects Problem description: Under IE, you can use () or [] to obtain collection objects; under Firefox, you can only use [ ] to obtain collection objects. object. Solution: Use [] uniformly to obtain collection objects.
3. Custom attribute issues Problem description: 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 obtain custom attributes. Solution: Get custom attributes through getAttribute().
4. eval("idName") problem Problem description: 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 id as idName. Solution: Use getElementById("idName") uniformly to obtain the HTML object with the id of idName.
5. The problem that the variable name is the same as the ID of an HTML object Problem description: Under IE, the ID of the HTML object can be used directly as the variable name of the subordinate object of document. Under Firefox Otherwise; under Firefox, you can use the same variable name as the HTML object ID, but not 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; when declaring variables, always add the var keyword to avoid ambiguity.
6. Const problem Problem description: Under Firefox, you can use the const keyword or the var keyword to define constants; under IE, you can only use the var keyword to define constants . Solution: Use the var keyword uniformly to define constants.
7. Problem with input.type attribute Problem description: The input.type attribute under IE is read-only; but the input.type attribute under Firefox is read-write. Solution: Do not modify the input.type attribute. If you must modify it, you can hide the original input first, and then insert a new input element at the same position.
8. Window.event problem Problem description: window.event can only be run under IE, but not under Firefox. This is because Firefox’s event can only be run under Used at the scene of the incident. Solution: Add the event parameter to the function where the event occurs, and use var myEvent = evt?evt:(window.event?window.event:null) in the function body (assuming the formal parameter is evt) Example :