问题描述
有没有人知道mozilla中span的innerText替代?
我的跨度是
Does any one know innerText alternative of a span in mozilla? My span is
<span id='cell1'></span>
和javascript是
and the javascript is
document.getElementById('cell1').innerText = 'Tenelol';
但是Mozilla不支持这个!!
But Mozilla is not supporting this!!
推荐答案
是IE专有的东西。 作为官方财产。
innerText
is a proprietary IE thing. The W3C defines textContent
as the official property.
一种简单的方法是利用 ||
逻辑运算符及其性质,以及JavaScript返回条件中的最后一个评估值(大部分时间是 truthy 操作数)。
An easy way is to exploit the ||
logical operator and its short circuiting nature, as well as JavaScript returning the last evaluated value in a condition (most times the truthy operand).
var body = document.body,
text = body.textContent || body.innerText;
。
(请注意我首先检查 innerText
的小提琴。只是因为这里的大多数人不使用IE.IRL,首先检查 textContent
,然后回退到 innerText
。 )
(Note in the fiddle I checked for the innerText
first. This was only because most people on here do not use IE. IRL, check for textContent
first, and fallback to innerText
.)
这篇关于Mozilla中的InnerText替代品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!