The following function receives a parameter, which can be an array or an element, and returns the text of the element.
function text(e){
var str = "";
//If an element is passed in, get its child elements
//Otherwise, when it is an array
e=e.childNodes || e;
for ( var i = 0; i < e.length; i ) {
//Determine the element type
//If it is text, get its text, otherwise, traverse its child elements
str = e[ i].nodeType != 1 ? e[i].nodeValue : text(e[i].childNodes);
}
return str;
}
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn