是< script src = foo>需要结束标记< / script> [英] Does <script src=foo> require an end tag </script>

查看:91
本文介绍了是< script src = foo>需要结束标记< / script>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

W3C HTML验证器传递了这个:


....

< script type =" text / javascript" src =" foo.js">


< script type =" text / javascript">

....脚本在这里...

< / script>

....


但据我所知,第一个脚本标记需要< / script>

关闭标记。有效标记是否需要关闭标记?我知道浏览器

接受这个,但那不是问题。它有效吗?

W3C HTML validator passes this:

....
<script type="text/javascript" src="foo.js">

<script type="text/javascript">
....script in here...
</script>
....

But as far as I can tell, the first script tag requires a </script>
close tag. Is the close tag required for valid markup? I know browsers
accept this, but that''s not the question. Is it valid?

推荐答案

rh*******@gmail.com 写道:
rh*******@gmail.com writes:
W3C HTML验证器传递此信息:


这里'是您的SCRIPT元素类型开始标记:

< script type =" text / javascript" SRC =" foo.js">


这里有一些任意的CDATA内容:

< script type =" text / javascript">
... script在这里......


这里是你的SCRIPT元素类型结束标记:

< / script>


下次,启用''查看解析树''(或者不管它叫什么,我都不能......)b
b b b 。

但据我所知,第一个脚本标记需要一个< / script>
关闭标记。


是的。好吧,结束标记。

有效标记需要关闭标记吗?


是的。

我知道浏览器
接受这个,


啊。我不是,我有太多关于他们对广义标记处理的一般性陈述



但这不是问题。它有效吗?
W3C HTML validator passes this:
Here''s your SCRIPT element type start tag:
<script type="text/javascript" src="foo.js">
Here''s some arbitrary CDATA content:
<script type="text/javascript">
...script in here...
Here''s your SCRIPT element type end tag:
</script>
Next time, enable ''view parse tree'' (or whatever it is called, I can''t
be bothered to have a look).
But as far as I can tell, the first script tag requires a </script>
close tag.
Yes. Well, end tag.
Is the close tag required for valid markup?
Yes.
I know browsers
accept this,
Ah. I don''t, I have too many of them to make generalised statements
about their treatment of generalized markup.
but that''s not the question. Is it valid?




是的。

(谁关心?)

-

|||十六进制EBB

oo十进制3771

--oOo - () - oOo--八进制7273

205再见二进制111010111011



Yes.
(who cares?)
--
||| hexadecimal EBB
o-o decimal 3771
--oOo--( )--oOo-- octal 7273
205 goodbye binary 111010111011


rhythmace写道:
rhythmace wrote:
< script type =" text / javascript" src =" foo.js">

< script type =" text / javascript">
...脚本在这里...
< / script>
...

但据我所知,第一个脚本标记需要一个< / script>
关闭标记。有效标记是否需要关闭标记?
<script type="text/javascript" src="foo.js">

<script type="text/javascript">
...script in here...
</script>
...

But as far as I can tell, the first script tag requires a </script>
close tag. Is the close tag required for valid markup?




是 - SCRIPT元素需要结束标记。但是你有一个结束标签

那里。


真正的问题是,你有多少个SCRIPT元素?

答案是一个。


第二个< script ... bit将被视为

第一个SCRIPT元素中的Javascript数据,并且应该导致Javascript错误(但不是

验证错误)。

-

Toby A Inkster BSc(荣誉)ARCS

联系我〜 http://tobyinkster.co.uk/contact



Yes -- the SCRIPT element requires an end tag. But you have an end tag
there.

The real question, is "how many SCRIPT elements do you have there?" The
answer is one.

The second "<script..." bit will be treated as Javascript data within the
first SCRIPT element, and should cause a Javascript error (but not a
validation error).

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact



rh*******@gmail.com 写道:
< script类型= QUOT;文本/ JavaScript的" src =" foo.js">

< script type =" text / javascript">
...脚本在这里...
< / script>
<script type="text/javascript" src="foo.js">

<script type="text/javascript">
...script in here...
</script>




已经解释了为什么这样的脚本声明不起作用。

我想提醒你另一个这种常见错误:


< script type =" text / javascript" src =" foo.js">

//这里的代码

< / script>


//代码这里的块将被忽略,只有foo.js代码将执行
(除非它是Netscape 2.xw / o src属性支持)


因此规则是:外部文件需要单独的< script>阻止

结束标记。


唯一可行的选项:


< script type =" text / JavaScript的" src =" foo.js">< / script>

< script type =" text / javascript">

//此处代码

< / script>



That was already explained why such script declaration will not work.
I''d just like to alert you about another common mistake of this kind:

<script type="text/javascript" src="foo.js">
// code here
</script>

// code here block will be ignored and only foo.js code will be
executed (unless it''s Netscape 2.x w/o src attribute support)

So the rule is: external file requires separate <script> block with
closing tag.

The only working option:

<script type="text/javascript" src="foo.js"></script>
<script type="text/javascript">
// code here
</script>


这篇关于是&lt; script src = foo&gt;需要结束标记&lt; / script&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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