[英]How to get textContent to work in Internet Explorer 8 (JavaScript)
我已将textContent应用于JavaScript中的div。 我无法使其在Internet Explorer中正常工作。 我如何使它在Internet Explorer 8中工作。我尝试这样做:
<div id="price"></div>
和:
document.getElementById("price").textContent = "GMGo is $5.00";
但没有显示文字“ GMGo为$ 5.00”
ie8不支持textContent
,但是有一种伪造它的方法:
http://eligrey.com/blog/post/textcontent-in-ie8
if (Object.defineProperty && Object.getOwnPropertyDescriptor &&
Object.getOwnPropertyDescriptor(Element.prototype, "textContent") &&
!Object.getOwnPropertyDescriptor(Element.prototype, "textContent").get)
(function() {
var innerText = Object.getOwnPropertyDescriptor(Element.prototype, "innerText");
Object.defineProperty(Element.prototype, "textContent",
{ // It won't work if you just drop in innerText.get
// and innerText.set or the whole descriptor.
get : function() {
return innerText.get.call(this)
},
set : function(x) {
return innerText.set.call(this, x)
}
}
);
})();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.