在 Document HEAD 中链接到外部脚本的最佳方式
我注意到许多网站都使用此功能,但没有关闭标签。
<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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你总是想使用
一些浏览器不允许自关闭脚本标签。
有关详细信息,请参阅为什么自关闭脚本标记不起作用?
You always want to use
Some browsers do not allow self-closing script tags.
For more information, see Why don't self-closing script tags work?
使用第二个选项。 并非所有浏览器都支持自关闭样式。
Use the second option. Not all browsers support the self-closing style.
这是无效的,并且会破坏东西。
这可以。
只要您使用的 XHTML 不 HTML 兼容。 这意味着您需要使用 XML 内容类型(最好是 application/xhtml+xml)来提供 XHTML,并且忘记支持 Internet Explorer(除非使用单独的文档)。
This is invalid, and will break things.
This is fine.
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).