运行该段HTML 文件: < script type = " text/javascript " > function test() {alert(document.getElementById("div1").innerText);} < / script> < div id = " div1 " > Hello world !< / div> < input type = " button " value = " OK " onclick = " test(); " / > 在IE 下,正常弹出“Hello world! ”;而在firefox 中,弹出的是“undefined ”的未定义错误; 现在用javascript 编写这样的一段代码: try { HTMLElement.prototype.__defineGetter__ ( "innerText", function () { var anyString = ""; var childS = this.childNodes; for(var i=0; i<childS.length; i++) { if(childS[i].nodeType==1) anyString += childS[i].tagName=="BR" ? '"n' : childS[i].innerText; else if(childS[i].nodeType==3) anyString += childS[i].nodeValue; } return anyString; } ); } catch (e) {} 在运行该段 HTML 文件,即可正常弹出“ Hello world !”了。