DOM构造和脚本执行 [英] DOM construction and script execution

查看:62
本文介绍了DOM构造和脚本执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




在以下片段和HTML页面中,是否有规范

保证foo元素将被解析并作为一部分提供

脚本执行时的DOM?也就是说,这个错误符合

标准的浏览器吗?



< script type =" text / javascript>

var foo = document.getElementById(''foo'');

< / script>


这似乎是非常常见的做法。如果这不是一个标准那么

也许这是所有浏览器都遵守的事实标准?


谢谢,

彼得

Hi,

In the following snip of and HTML page, is there a specification
guarantee that the foo element will be parsed and available as part of
the DOM by the time the script executes? That is, could this error in a
standards-compliant browser?

<p id="foo">foo</p>

<script type="text/javascript>
var foo = document.getElementById(''foo'');
</script>

This seems to be very common practice. If this is not a standard then
perhaps this is a de facto standard that all browsers honour?

Thank you,
Peter

推荐答案

Peter Michaux于2007年1月27日在comp.lang.javascript上写道
Peter Michaux wrote on 27 jan 2007 in comp.lang.javascript:

在以下片段和HTML页面中,是否有规范

保证foo元素将被解析并作为
脚本执行时,DOM是
?也就是说,这个错误符合

标准兼容的浏览器吗?
In the following snip of and HTML page, is there a specification
guarantee that the foo element will be parsed and available as part of
the DOM by the time the script executes? That is, could this error in a
standards-compliant browser?



Methinks还没有符合标准的浏览器。

从来没有,

[长因为标准是针对的目标。

Methinks there are NO standards-compliant browsers yet.
There never will be,
as [long as] standards are something to aim at.


< p id =" foo"> foo< / p>


< script type =" text / javascript>

var foo = document.getElementById(''foo'');

< / script>


这似乎是很常见的做法。如果这不是一个标准那么

也许这是事实上的标准...
<p id="foo">foo</p>

<script type="text/javascript>
var foo = document.getElementById(''foo'');
</script>

This seems to be very common practice. If this is not a standard then
perhaps this is a de facto standard ...



这本身并不是标准。


foo不会成为DOM的一部分,

但是是指向DOM元素的javascript变量,

[感知者javascript作为一个对象,我想]。


....所有浏览器都尊重它?


不,不是全部 。

总会有浏览器,比如非常旧的版本,不会,但是可以放心,大多数现代版本和大多数观众卷都会这样做。


-

Evertjan。

荷兰。

(请将x''es更改为圆点在我的电子邮件中)

It is not an standars per se.

foo will not be part of the DOM,
but is a javascript variable pointing to a DOM element,
[perceivesd by javascript as being an object, I think].

.... that all browsers honour?

No, not "all".
There always will be browsers, like very old versions, that will not,
but be assured that most modern ones and most ones audience volume wize do.

--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)


1月27日凌晨1点06分,Evertjan。 < exjxw.hannivo ... @interxnl.netwrote:
On Jan 27, 1:06 am, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:

< p id =" foo"> foo< / p为H.
<p id="foo">foo</p>


< script type =" text / javascript>

var foo = document.getElementById(''foo' ');

< / script>
<script type="text/javascript>
var foo = document.getElementById(''foo'');
</script>


这似乎是很常见的做法。如果这不是一个标准那么

也许这是事实上的标准......它本身并不是标准。
This seems to be very common practice. If this is not a standard then
perhaps this is a de facto standard ...It is not an standars per se.



foo不会成为DOM的一部分,

但是是一个指向DOM元素的javascript变量,

[我认为通过javascript认为是一个对象]。


foo will not be part of the DOM,
but is a javascript variable pointing to a DOM element,
[perceivesd by javascript as being an object, I think].



让我用不同的字符串更清楚。


< p id =" myPara"> asdf< ; / p>


< script type =" text / javascript>

var foo = document.getElementById(''myPara'');

< / script>

因此在IE5和NN6之前排除浏览器或没有

document.getElementById,有没有人知道一个这个JavaScript运行或不会返回myPara时会出错的浏览器

元素

当调用document.getElementById()时?


谢谢,

彼得

Let me make that more clear with different strings.

<p id="myPara">asdf</p>

<script type="text/javascript>
var foo = document.getElementById(''myPara'');
</script>

So excluding browsers before IE5 and NN6 or without
document.getElementById, does anyone know of a browser that will error
when this JavaScript runs or that will not return the "myPara" element
when document.getElementById() is called?

Thanks,
Peter


Peter Michaux于2007年1月27日在comp.lang.javascript写了
Peter Michaux wrote on 27 jan 2007 in comp.lang.javascript:

1月27日,凌晨1点06分,Evertjan。 < exjxw.hannivo ... @interxnl.netwrote:
On Jan 27, 1:06 am, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:

< p id =" foo"> foo< / p为H.
<p id="foo">foo</p>


< script type =" text / javascript>

var foo = document.getElementById(''foo' ');

< / script>
<script type="text/javascript>
var foo = document.getElementById(''foo'');
</script>


这似乎是很常见的做法。如果这不是一个标准的

那么也许这是事实上的标准......这不是一个标准

本身。
This seems to be very common practice. If this is not a standard
then perhaps this is a de facto standard ...It is not an standars
per se.


foo不会成为DOM的一部分,
但是是指向DOM元素的javascript变量,
[被javascript视为对象,我认为]。


foo will not be part of the DOM,
but is a javascript variable pointing to a DOM element,
[perceivesd by javascript as being an object, I think].



让我用不同的字符串更清楚。


< p id =" myPara"> asdf< ; / p>


< script type =" text / javascript>

var foo = document.getElementById(''myPara'');

< / script>

因此在IE5和NN6之前排除浏览器或没有

document.getElementById,有没有人知道一个这个JavaScript运行或不会返回myPara时会出错的浏览器

元素

调用document.getElementById()时?


Let me make that more clear with different strings.

<p id="myPara">asdf</p>

<script type="text/javascript>
var foo = document.getElementById(''myPara'');
</script>

So excluding browsers before IE5 and NN6 or without
document.getElementById, does anyone know of a browser that will error
when this JavaScript runs or that will not return the "myPara" element
when document.getElementById() is called?



如果您希望偶尔使用这些旧浏览器,

您可以测试功能:


< p id =" myPara"> asdf< / p>


if(document.getElementById(''myPara'')){

var foo = document.getElementById(''myPara'');


/ /其余代码


}

< / script>


-

Evertjan。

荷兰。

(请在我的电子邮件地址中将x'变为点数)

If you expect those old browser to be used occasionally,
you could test for the functionality:

<p id="myPara">asdf</p>

<script type="text/javascript>
if (document.getElementById(''myPara'')){
var foo = document.getElementById(''myPara'');

// rest of code

}
</script>

--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)


这篇关于DOM构造和脚本执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆