今天学习Buffalo,国人开发的一个Web远程调用(WebRemoting)的库。调试burlap的协议的时候,使用JS+innerText显示,发现在Firefox中不能正常。深入了解后,才发现日常已经非常熟悉的IE里的innerText,innerHTML属性,居然都不是W3C的标准。
The following element properties (originally from Internet Explorer) are likewise not supported in the W3C Document Object Model:
* element.innerText
* element.innerHTML
* element.outerText
* element.outerHTML
目前在实际应用中,innerHTML是现实的标准FF,IE都支持,innerText只有IE支持,FF使用的是标准的W3C标准textContent 。
在实际使用中innerText中,如果分IE,FF来分别撰写代码,又增加了很多工作量,尤其在ajax开发中,会大量用到innerText属性。
还好在Mozilla FireFox中国社区(http://www.firefox.net.cn/newforum/viewtopic.php?t=4306)招到了一个解决方案:
把这段加在你所JS文件中就可以在MOZILLA/FIREFOX下使用innerText
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;
}
);
但这段代码在IE中它会提示HTMLElement未定义,暂时我还没有找到解决方法。
但这段代码在IE中它会提示HTMLElement未定义,暂时我还没有找到解决方法。
以上代码在IE6,FireFox1.0.3下测试通过,希望在IE5.5也能通过测试,通过web log分析,IE5.5,IE6还是占了很大的份额。
另外还有《IE与Mozilla下Dhtml的一些区别小结》可以看看。
http://www.yesky.com/club/topic/173/1332081.html
Trackback: http://tb.donews.net/TrackBack.aspx?PostId=398198