开发者

<script> tag must include separate </script> tag?

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!


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜