Home > Article > Web Front-end > Summary of modifications to FF IE compatibility_javascript skills
1. If the html tag uses the two methods $(id) or getElementById to obtain the value, the id attribute must be added to the tag to be compatible with IE and FF. For example, $(mobile): If you fill in the mobile input without the id attribute, the variable will be reported as undefined in FF;
2. Get a label object of the form form. If you want IE and FF compatibility, you need to change formMain.item to document.formName.item.
For example, form1.webUrl is changed to document.form1.webUrl.
If form is passed as a parameter to a function, "document." must also be added, such as search(formMain) changed to search(document.formMain)
3. Use obj. to get the custom attributes of html. If attributeName is changed to obj.getAttribute("attributeName"), it will be compatible with IE and FF; non-custom attributes can still be obtained according to
obj.attributeName.
For example: The checkValue attribute in this tag is a custom attribute. It needs to be obtained using obj.getAttribute("checkValue"). It is only compatible with IE and FF. Other attributes such as the type attribute can still be obtained using obj.type.
4. The eval function is used differently in FF and IE. When an executable statement connected with " " is used as the parameter of eval in FF, it cannot be executed, but it can be used in IE. When you encounter the need to use eval, try to find other methods instead.
For example: eval("msg_" textbox.name ".className='wrong'");
"msg_" textbox.name ".className='wrong'" is used as a parameter of eval in IE It can be executed. When executing in FF, it reports "msg_" textbox.name. The space name obtained by the connection is undefined. It cannot be executed. It needs to be modified to:
document.getElementById("msg_" textbox.name).className='wrong';
5. The display attribute block in the style can become empty if an exception is encountered in FF; for example, item.style.display="block" can be changed to item.style.display=""
For example, $ ("divType4").style.display="block";
Changed to $("divType4").style.display="";
6. Add another one: label seems to be different from IE in FF Same: For example, the following code: