IE and FireFox JavaScript compatibility problem solution

  • 2020-03-30 01:11:58
  • OfStack

Here's what happened to me during development:

1. Dynamically delete a row in the table.

Table: represents the table object.

K: represents the line number

A table. Rows [k]. RemoveNode (true); //firefox failed, ie succeeded

IE is compatible with FireFox

Table. DeleteRow (k);

2. Customize attributes for HTML tags.

InputElement: represents a form element.

PropertyName: represents a property under a form element

InputElement. PropertyName; //firefox failed, ie succeeded

IE is compatible with FireFox

Document. The getElementById (" txtInput "). The attributes [r]. "idvalue nodeValue

Insert an HTML element at the specified location.

InputElement: represents a form element.

VDiv: represents the HTML element to be inserted.

InputElement. InsertAdjacentElement (" AfterEnd vDiv); //firefox failed, ie succeeded

IE is compatible with FireFox

In firefox, there is no definition for this method, so if you need to call it, you need to redefine it yourself.

//Rewrite the insertAdjacentElement () method, because no the method in firefox
                    case "beforeBegin":
                    case "afterBegin":
                    case "beforeEnd":
                    case "afterEnd":

4. The break statement is invalid.

Break was originally used to break out of the for loop in IE. But in FF it becomes exiting the loop. Instead, use the continue statement.

5. Firefox contains an invalid character.

Var chkBox = document. The createElement method (' < Input type="Checkbox" name="treeBox" value= '+key+'> '); // successfully executed under IE

IE is compatible with FireFox

IE is compatible with FireFox

bdList.rows[k].cells[0].innerHTML = "<a>aaa</a>";

7, JS getYear() method in firefox

Var today = new date();
Var year = today. GetYear ();
GetYear in Firefox returns the value of "current year -1900" in IE:
When today's year is less than 2000, it's the same as firefox. So it's better to call getFullYear getUTCFullYear

IE is compatible with FireFox

var today = new date(); 
var year = today.getFullYear(); 

Related articles: