12345678910111213141516171819202122 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <div id="vase">
- <h1 id="happy">
- 你好
- </h1>
- </div>
- <script>
- var content = document.getElementById("vase");
- alert(content.innerHTML);
- // innerHTML 解析的是开始标签与结束标签的所有内容
- alert(content.innerText);
- // innerText 解析的是开始标签与结束标签的中间的文本内容
- </script>
- </body>
- </html>
|