Sya*_*ien 3 html javascript text
这就是我要做的...
alert(document.getElementById('test').innerHTML);Run Code Online (Sandbox Code Playgroud)
<div id="test">
hi..my name is <div>Soul</div> and I am <strong>23 years old</strong>
Thank you.
</div>Run Code Online (Sandbox Code Playgroud)
警报框将显示:
hi..my name is <div>Soul</div> and I am <strong>23 years old</strong>Thank you.
Run Code Online (Sandbox Code Playgroud)
但我想要在 ALERT BOX 中的是:
hi..my name is Soul and I am 23 years old Thank you.
Run Code Online (Sandbox Code Playgroud)
使用textContent而不是innerHTML获取文本内容而不是标记
console.log(document.getElementById('test').textContent);Run Code Online (Sandbox Code Playgroud)
<div id="test">
hi..my name is <div>Soul</div> and I am <strong>23 years old</strong>
Thank you.
</div>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1894 次 |
| 最近记录: |