JS. getTextContent: the text for obtaining tags must be familiar to everyone. The following describes how to use tags. For more information, see.
The Code is as follows:
/* Obtain the label text */
Function getTextContent (element, preformatted ){
If (! ElementIsVisible (element) return '';
If (element. nodeType = 3/* Node. TEXT_NODE */){
Var text = element. data;
If (! Preformatted ){
// Text = text. replace (/\ n | \ r | \ t/g ,"");
Text = normalizeNewlines (text );
}
Return text;
}
If (element. nodeType = 1/* Node. ELEMENT_NODE */& element. nodeName! = 'Script '){
Var childrenPreformatted = preformatted | (element. tagName = "PRE ");
Var text = "";
For (var I = 0; I <element. childNodes. length; I ++ ){
Var child = element. childNodes. item (I );
Text + = getTextContent (child, childrenPreformatted );
}
// Handle block elements that introduce newlines
// -- From HTML spec:
// // "P | % heading; | % list; | % preformatted; | DL | DIV | NOSCRIPT |
// BLOCKQUOTE | F: wORM | HR | TABLE | FIELDSET | ADDRESS ">
//
// TODO: shocould potentially introduce multiple newlines to separate blocks
If (element. tagName = "P" | element. tagName = "TR" | element. tagName = "BR" | element. tagName = "HR" | element. tagName = "DIV "){
Text + = "\ n ";
}
Return text;
}
Return '';
}
/* Whether the element is visible */
Function elementIsVisible (element)
{
If (element. style. visiablity = "hidden" | element. style. display = "none ")
Return false;
Else
Return true;
}