<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <p>我正在学习JavaScript编程技术</p> <p>我正在学习<strong style="color: red;">JavaScript</strong>编程技术</p> </body> <script> var p = document.getElementsByTagName('p')[0]; var p1 = document.getElementsByTagName('p').item(1); console.log(p.innerHTML); //innerHTML可以输出标签 console.log(p1.innerHTML) //textContent 仅获取纯文本 console.log(p.textContent); console.log(p1.textContent); //nodeType == 3 文本节点 //nodeValue 节点值 if(p.childNodes[0].nodeType == 3){ console.log(p.childNodes[0].nodeValue); } if(p1.childNodes[0].nodeType == 3){ console.log(p1.childNodes[0].nodeValue); } </script> </html>