Comments: With the rapid development of science and technology, various browsers emerge one after another. Recently, many projects require supporting all kinds of browsers such as IE and FireFox at the same time, which has suffered a lot. In particular, I am used to this habit, such: "event. srcElement "," outerHTML ", and" parentElement. Many handy objects and methods used in IE, in W3C Standard
The Code is as follows:
The Code is as follows:
Var pro = window. HTMLElement. prototype;
Pro. _ defineGetter _ ("outerHTML", function (){
Var str = "<" + this. tagName;
Var a = this. attributes;
For (var I = 0, len = a. length; I <len; I ++ ){
If (a [I]. specified ){
Str + = "" + a [I]. name + '= "' + a [I]. value + '"';
}
}
If (! This. canHaveChildren ){
Return str + "/> ";
}
Return str + ">" + this. innerHTML + "</" + this. tagName + "> ";
});
Pro. _ defineSetter _ ("outerHTML", function (s ){
Var r = this. ownerDocument. createRange ();
R. setStartBefore (this );
Var df = r. createContextualFragment (s );
This. parentNode. replaceChild (df, this );
Return s;
});
Pro. _ defineGetter _ ("canHaveChildren", function (){
Return! /^ (Area | base | basefont | col | frame | hr | img | br | input | isindex | link | meta | param) $ /. test (this. tagName. toLowerCase ());
});