We know that the innerHTML attribute with the browser itself can get the value of the string contained in the node, such as the following nodes:
Copy Code code as follows:
<div id= "test" ><strong>i ' m strong</strong></div>
Pass
Copy Code code as follows:
var Obj=document.getelementbyid ("Test"); alert (obj.innerhtml);//The value returned is <strong>i ' m strong</strong>
If I want to get the text value of the node, it does not include the string that the label is supposed to do. The text value here is: I ' m strong
Non-Mozilla browsers: obj.innertext;//other browsers obj.firstChild.nodeValue;
First, provide a common way to resolve compatibility issues:
The complete code is as follows:
Code
<ptml> <pead> <title>title</title> </pead> <body> <div id= "test" ><stron G>i ' m strong</strong></div> <script type= "Text/javascript" > var Obj=document.getelementbyid (" Test "); Compatible browsers Get node text method function text (e) {var t= ""; If the element is passed in, it continues to traverse its child elements//Otherwise assume it is an array e=e.childnodes| | E Iterate through all child nodes for (Var j=0;j<e.length;j++) {//If not element, append its text value/otherwise, recursively iterate through the child nodes of all elements T+=e[j].nodetype!=1?e[j].nodevalue:text (E[j].childnodes); }//Return area with the text returned T; Alert (text (obj)) </script> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
Let Firefox support the innertext implementation code
Reprint please indicate from: http://www.cnblogs.com/wbkt2t/