Firefox& IE不运行innertext

时间:2013-09-13 09:29:12

标签: javascript

我遇到这样的问题:

<div id='stickyid' style='display:block; color:red'>happi</div>
After write :
<script type="text/javascript">
var thevalue = document.getElementById("stickyid").innerText;
document.write(""+thevalue+""); 
</script>

它在Chrome上运行正常但在Firefox和IE上运行不正常。我该如何解决?

2 个答案:

答案 0 :(得分:5)

尝试:

var thevalue = document.getElementById("stickyid").innerText || document.getElementById("stickyid").textContent;

答案 1 :(得分:2)

演示:http://jsfiddle.net/E3ESv/

var thevalue = document.getElementById("stickyid").textContent;

请访问'innerText' works in IE, but not in Firefox获取更多帮助