<脚本>标签必须包含单独的标签?

发布于 2024-11-10 09:58:55 字数 372 浏览 2 评论 0原文

今天,我在进行一些测试时注意到,关闭

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

但这不起作用:

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

当我使用 IE 的开发人员工具时,该文件似乎会显示,但似乎它只是被忽略了。有谁见过这种情况或知道为什么会发生这种情况?提前致谢!

I noticed today while doing some testing that the way I close my <script> tag either makes or breaks my page. For example, this works:

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

but this does not:

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

The file appears to show up when I use IE's Developer Tools, but it seems like it just gets ignored. Has anyone ever seen this or know why it might be happening? Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

分分钟 2024-11-17 09:58:55

您必须包含结束脚本标记。即使您只包含外部脚本,脚本元素也不会自动关闭。

You must include a closing script tag. The script element is not self closing, even when you're only including an external script.

携君以终年 2024-11-17 09:58:55

在所有其他 HTML 文档中(无论声明什么 DOCTYPE),关闭。

在这个非常详细的答案中阅读更多内容。

The <script> tag can only be self-closing in truly valid XHTML documents – that is, a XHTML page served with the Content-Type of application/xhtml+xmland when viewed in a supporting browser (IE8 does not qualify; IE9+ does).

In all other HTML documents, (regardless of what DOCTYPE is declared), the <script> tag is not self-closing and therefore must be closed with a </script>.

Read more in this very detailed answer.

你不是我要的菜∠ 2024-11-17 09:58:55

我还注意到您始终需要。这可能是因为它需要标签之间的内容(“”计数),即使您使用的是 src

I have also noticed you always need the </script>. It's probably because it requires content between the tags ("" counts), even though you're using src.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文