The innerText attribute can be used in IE browsers to obtain the text content after HTML Tags is filtered out by the current element, which is useful in some cases. However, similar non-standard attributes/methods are not necessarily supported in other browsers.
Such as insertAdjacentElement, insertAdjacentElement, insertAdjacentHTML, and insertAdjacentText. If you need to use these non-standard methods or the existing Code uses these methods in large quantities, you must provide prototype definitions for other browsers. For example:
Var isMinNS5 = (navigator. appName. indexOf ("Netscape")> = 0 &&
ParseFloat (navigator. appVersion)> = 5 )? 1: 0;
If (isMinNS5 ){
HTMLElement. prototype. insertAdjacentElement = function (where, parsedNode ){
Switch (where ){
Case beforeBegin:
This. parentNode. insertBefore (parsedNode, this)
Break;
Case afterBegin:
This. insertBefore (parsedNode, this. firstChild );
Break;
Case beforeEnd:
This. appendChild (parsedNode );
Break;
Case afterEnd:
If (this. nextSibling ){
This. parentNode. insertBefore (parsedNode, this. nextSibling );
}
Else {
This. parentNode. appendChild (parsedNode)
}
Break;
}
}
HTMLElement. prototype. insertAdjacentHTML = function (where, htmlStr ){
Var r = this. ownerDocument. createRange ();
R. setStartBefore (this );
Var parsedHTML = r. createContextualFragment (htmlStr );
This. appendChild (parsedHTML)
}
HTMLElement. prototype. insertAdjacentText = function (where, txtStr ){
Var parsedText = document. createTextNode (txtStr)
This. insertAdjacentElement (where, parsedText)
}
HTMLElement. prototype. _ defineGetter __
(
"InnerText ",
Function (){
Var anyString = "";
Var childS = this. childNodes;
For (var I = 0; I <childS. length; I ++ ){
If (childS [I]. nodeType = 1)
AnyString + = childS [I]. tagName = "BR "? \ N: childS [I]. innerText;
Else if (childS [I]. nodeType = 3)
AnyString + = childS [I]. nodeValue;
}
Return anyString;
}
);
}