Home >Web Front-end >JS Tutorial >Solutions to JavaScript compatibility issues between IE and FireFox_javascript tips
The following is what I encountered during development:
1. Dynamically delete a row in the table.
table: represents table object.
k: represents line number
table.rows[k].removeNode(true); //firefox execution failed, ie execution succeeded
IE and FireFox compatible writing
table.deleteRow(k);
2. Customize attributes for HTML tags.
inputElement: represents a form element.
propertyName: represents a certain property under the form element
inputElement.propertyName; //firefox execution failed, ie execution succeeded
IE and FireFox compatible writing method
document.getElementById("txtInput").attributes["idvalue"].nodeValue
3. Insert an HTML element at the specified position.
inputElement: Represents a form element.
vDiv: Represents the HTML element to be inserted.
inputElement.insertAdjacentElement("AfterEnd",vDiv);//firefox execution failed, ie execution was successful
IE and FireFox compatible writing
In Firefox, there is no definition of this method, so if you need to call this method, you need to redefine it yourself.
When executing a for loop statement in IE, break can be used to jump out of the current loop. But in FF, it becomes exiting the entire loop. At this time, use the continue statement instead.
5. Firefox reports that String contains an invalid character.
var chkBox=document.createElement(''); //Successfully executed under IE
IE and FireFox compatible writing
Firefox does not support this way of defining createElement and needs to be done step by step:
chkBox.value = key;
IE and FireFox compatible writing
var today = new date();
var year = today.getYear();
In Firefox, getYear returns the value of "current year-1900". In IE:
When today When the year is less than 2000, it is the same as Firefox. So it’s best to use getFullYear getUTCFulYear to call
IE and FireFox compatible writing