没有html的innerHTML,只是文本 [英] innerHTML without the html, just text
问题描述
我创建了一个电子邮件链接,可以自动填充正文中的必要信息。但是,当我做.innerHTML时,我得到的比我讨价还价多一点。
我想要2012年3月:12-16
我得到< B> 2012年3月< / B>:< FONT color = blue> 12< / FONT> - < FONT颜色=蓝色> 16< / FONT>
是否有一种方式来获得的innerHTML而不html标签
.value =未定义
$ p $在所有年龄段的IE浏览器中都需要
.text = undefined
.textContent
,<$ c> (< 9)。
所以,试试: b
string =(node.textContent === undefined)? node.innerText:node.textContent;
编辑:或,只是使用GGG的干净多了
string =(node.innerText || node.textContent)
,因为undefined
是虚假的。I've created an e-mail link that automatically populates the necessary information in the body. But, when I do .innerHTML I get a little more than I bargained for.
I want "March, 2012: 12-16"
What I get
<B>March, 2012</B>: <FONT color=blue>12</FONT> - <FONT color=blue>16</FONT>
Is there a way to get the innerHTML without the html tags?
.value = undefined .text = undefined
解决方案You want
.textContent
in all but older IE, and.innerText
in IE (<9).So, try:
string = (node.textContent===undefined) ? node.innerText : node.textContent;
EDIT: Or, just use GGG's much cleaner
string = (node.innerText || node.textContent)
, sinceundefined
is falsy.这篇关于没有html的innerHTML,只是文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!