只需要在页面加载的时候加入下面的代码
1. //让火狐支持innerText
2. (function(bool) {
3. function setInnerText(o, s) {
4. while (o.childNodes.length != 0) {
5. o.removeChild(o.childNodes[0]);
6. }
7.
8. o.appendChild(document.createTextNode(s));
9. }
10.
11. function getInnerText(o) {
12. var sRet = "";
13.
14. for (var i = 0; i < o.childNodes.length; i++) {
15. if (o.childNodes[i].childNodes.length != 0) {
16. sRet += getInnerText(o.childNodes[i]);
17. }
18.
19. if (o.childNodes[i].nodeValue) {
20. if (o.currentStyle.display == "block") {
21. sRet += o.childNodes[i].nodeValue + ""n";
22. } else {
23. sRet += o.childNodes[i].nodeValue;
24. }
25. }
26. }
27.
28. return sRet;
29. }
30.
31. if (bool) {
32. HTMLElement.prototype.__defineGetter__("currentStyle", function() {
33. return this.ownerDocument.defaultView.getComputedStyle(this, null);
34. });
35.
36. HTMLElement.prototype.__defineGetter__("innerText", function() {
37. return getInnerText(this);
38. })
39.
40. HTMLElement.prototype.__defineSetter__("innerText", function(s) {
41. setInnerText(this, s);
42. })
43. }
44. })(/Firefox/.test(window.navigator.userAgent));
然后就能使用object.innerText了
浙公网安备 33010602011771号