9

为什么浏览器无法正确识别自闭合的script标签?

 3 years ago
source link: http://coding2live.com/detail/81/%E4%B8%BA%E4%BB%80%E4%B9%88%E6%B5%8F%E8%A7%88%E5%99%A8%E6%97%A0%E6%B3%95%E6%AD%A3%E7%A1%AE%E8%AF%86%E5%88%AB%E8%87%AA%E9%97%AD%E5%90%88%E7%9A%84script%E6%A0%87%E7%AD%BE%EF%BC%9F
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

为什么浏览器无法正确识别自闭合的script标签?

coding2live 2021-02-14 11:49:16 0 102 javascript, html, internet-explorer, xhtml

浏览器不能正确识别下面写法(自闭合标签)的原因是什么:

<script src="foobar.js" /> <!-- self-closing script element -->

只有下面的写法是可以被正确识别的:

<script src="foobar.js"></script>

这是否破坏了XHTML支持的概念?

以下答案仅供参考

XHTML 1规范说明如下:

Given an empty instance of an element whose content model is not EMPTY (for example, an empty title or paragraph) do not use the minimized form (e.g. use <p> </p> and not <p />).
coding2live简译 对于标签内可以包含内容的标签,即便其内容为空,也不要使用自闭合形式的缩写。(例如使用<p> </p>而不是<p />)。

XHTML DTD指定脚本元素如下:

<!-- script statements, which may include CDATA sections -->
<!ELEMENT script (#PCDATA)>
电报频道: 划水摸鱼爱好者 Q Q 群聊: 993137424 站长微信: read-write-code

友情链接 添加友链请发送邮件至:onebookman#foxmail.com


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK