<div class="codetitle"> <span><a style="CURSOR: pointer" data="20585" class="copybut" id="copybut20585" onclick="doCopy('code20585')"><u>複製程式碼</u></a></span> 程式碼如下:</div> <div class="codebody" id="code20585"> <br>var text = ''; <br>$('div') .contents().each(function(){ <br>if(this.nodeType === 3){ <br>text = this.wholeText; <br>} <br>}); <br> </div> <br><strong>nodeType<br></strong> <table class="jbborder"> <tbody> <tr> <td>元素element </td> <td>1 </td> </tr> <tr> <td>属性attr </td> <td>2 </td> </tr> <tr> <td>文本text </td> <td>3 </td> </tr> <tr> <td>注释comments </td> <td>8 </td> </tr> <tr> <td>文档document </td> <td>9 </td> </tr> </tbody> </table>