在W3C之前的DOM浏览器上模拟document.documentElement [英] emulating document.documentElement on pre W3C DOM browsers
问题描述
(请告诉我这是不是很傻或者我正在吠叫错误的树)
有人可以在W3C之前的DOM浏览器上查看这个吗: -
函数getDocumentRoot()
{
for(e in document.childNodes)
if(document.childNodes [e] .nodeName ==" HTML")
return document.childNodes [e];
return document.body;
}
if(!document.documentElement)
document.documentElement = getDocumentRoot();
这里有一个html测试页面: -
http://www.aarongray.org/Test/JavaSc...ment-test.html
还有这里对document.getElementById()仿真进行测试: -
http://www.aarongray.o rg / Test / JavaSc ... ById-test.html
非常感谢提前,
Aaron >
推荐答案
" Aaron Gray" < an ******** @ gmail.comwrote in message
news:6d ************ @ mid.individual.net ...
"Aaron Gray" <an********@gmail.comwrote in message
news:6d************@mid.individual.net...
if(!document.documentElement)
document.documentElement = getDocumentRoot();
if (!document.documentElement)
document.documentElement = getDocumentRoot();
次要行为修正: -
if(!document.documentElement)
{
document.documentElement = getDocumentRoot();
document.documentElement.readOnly = true;
}
Aaron
Minor behavioural amendment :-
if (!document.documentElement)
{
document.documentElement = getDocumentRoot();
document.documentElement.readOnly = true;
}
Aaron
Aaron Grayaécrit:
Aaron Gray a écrit :
" Aaron Gray" < an ******** @ gmail.comwrote in message
news:6d ************ @ mid.individual.net ...
"Aaron Gray" <an********@gmail.comwrote in message
news:6d************@mid.individual.net...
您的页面测试适用于我的Fx.3
(虽然它不符合W3C)
Your page-test works well with my Fx.3
(while it is not W3C compliant)
> if(!document.documentElement)
document.documentElement = getDocumentRoot();
> if (!document.documentElement)
document.documentElement = getDocumentRoot();
次要行为修正: -
if(!document.documentElement)
{
document.documentElement = getDocumentRoot();
Minor behavioural amendment :-
if (!document.documentElement)
{
document.documentElement = getDocumentRoot();
我的想法是不会使用下一行。
''HTML''已写在页面上
因此,可能没有更多现有的JS。
on my idea the next line will be not used.
''HTML'' has been written on the page
so, probably, there is no more existing JS.
document.documentElement.readOnly = true;
}
document.documentElement.readOnly = true;
}
if(!document.documentElement)
{
document.documentElement = getDocumentRoot();
document.documentElement.readOnly = true;
alert(''vu'');
}
警报没有开火
-
sm
if (!document.documentElement)
{
document.documentElement = getDocumentRoot();
document.documentElement.readOnly = true;
alert(''vu'');
}
the alert doesn''t fire
--
sm
" ; SAM" < st ********************* @ wanadoo.fr.invalidwrote in message
news:48 ******* ************** @ news.orange.fr ...
"SAM" <st*********************@wanadoo.fr.invalidwrote in message
news:48*********************@news.orange.fr...
Aaron Grayaécrit:
Aaron Gray a écrit :
>" Aaron Gray" < a ******** @ gmail.comwrote in message
新闻:6d ************ @ mid.individual.net ...
>"Aaron Gray" <an********@gmail.comwrote in message
news:6d************@mid.individual.net...
您的页面测试适用于我的Fx.3
(虽然它不符合W3C标准)
Your page-test works well with my Fx.3
(while it is not W3C compliant)
>> if(!document.documentElement)
document.documentElement = getDocumentRoot();
>> if (!document.documentElement)
document.documentElement = getDocumentRoot();
次要行为修正: -
if(!document.documentElement)
{/> document.documentElement = getDocumentRoot();
Minor behavioural amendment :-
if (!document.documentElement)
{
document.documentElement = getDocumentRoot();
关于我的想法,下一行将不会被使用。
''HTML''已写在页面上
因此,可能没有更多现有的JS。
on my idea the next line will be not used.
''HTML'' has been written on the page
so, probably, there is no more existing JS.
太棒了。
Great.
> document.documentElement.readOnly = true;
}
> document.documentElement.readOnly = true;
}
if(!document.documentElement)
{
document.documentElement = getDocumentRoot();
document.documentElement.readOnly = true;
alert(''vu'');
}
警报不会触发
if (!document.documentElement)
{
document.documentElement = getDocumentRoot();
document.documentElement.readOnly = true;
alert(''vu'');
}
the alert doesn''t fire
好的Fx.3当时不支持readOnly属性。
多亏了AFAICS并没有真正解决这个问题:(
Aaron
Okay Fx.3 does not support the readOnly attribute then.
Thats annoying as AFAICS theres no real fix for that :(
Aaron
这篇关于在W3C之前的DOM浏览器上模拟document.documentElement的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!