Home > Web Front-end > JS Tutorial > Javascript solves innerText browser compatibility problem code_javascript skills

Javascript solves innerText browser compatibility problem code_javascript skills

WBOY
Release: 2016-05-16 17:33:34
Original
919 people have browsed it

The following function receives a parameter, which can be an array or an element, and returns the text of the element.

Copy code The code is as follows:

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;
}
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template