没有html的innerHTML,只是文本 [英] innerHTML without the html, just text

查看:103
本文介绍了没有html的innerHTML,只是文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个电子邮件链接,可以自动填充正文中的必要信息。但是,当我做.innerHTML时,我得到的比我讨价还价多一点。



我想要2012年3月:12-16



我得到< B> 2012年3月< / B>:< FONT color = blue> 12< / FONT> - < FONT颜色=蓝色> 16< / FONT>



是否有一种方式来获得的innerHTML而不html标签

  .value =未定义
.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), since undefined is falsy.

这篇关于没有html的innerHTML,只是文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆