在 Document HEAD 中链接到外部脚本的最佳方式

发布于 2024-07-23 08:12:55 字数 429 浏览 19 评论 0原文

我注意到许多网站都使用此功能,但没有关闭标签。

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

这种风格也是推荐,但较长:

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

我可以这样写吗? 它有效还是有更好的方法?

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

I've noticed many sites use this, without closing the tag.

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

This style is also recommended but is longer:

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

Can I write it like this? Is it valid or is there a better way?

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

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

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

发布评论

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

评论(3

尹雨沫 2024-07-30 08:12:55

你总是想使用

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

一些浏览器不允许自关闭脚本标签。

有关详细信息,请参阅为什么自关闭脚本标记不起作用?

You always want to use

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

Some browsers do not allow self-closing script tags.

For more information, see Why don't self-closing script tags work?

楠木可依 2024-07-30 08:12:55

使用第二个选项。 并非所有浏览器都支持自关闭样式。

Use the second option. Not all browsers support the self-closing style.

自演自醉 2024-07-30 08:12:55
<script type="text/javascript" src="editor.js">

这是无效的,并且会破坏东西。

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

这可以。

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

只要您使用的 XHTML 不 HTML 兼容。 这意味着您需要使用 XML 内容类型(最好是 application/xhtml+xml)来提供 XHTML,并且忘记支持 Internet Explorer(除非使用单独的文档)。

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

This is invalid, and will break things.

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

This is fine.

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

This is fine so long as you are using XHTML that is not HTML Compatible. This means you need to serve the XHTML with an XML content-type (preferably application/xhtml+xml) and forget about supporting Internet Explorer (except with a separate document).

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