在HTML中包含JavaScript文件不会像< script .... /> [英] Include JavaScript file in HTML won't work as <script .... />
本文介绍了在HTML中包含JavaScript文件不会像< script .... />的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在网站的每个页面上都包含一个JavaScript文件。我可以这样做:
< script type =text / javascriptsrc =myFile.js><< ; /脚本>
这个工作正常 - 但由于两个标签之间没有任何内容,所以我想将其更改为:
< script type =text / javascriptsrc =myFile.js/>
如果我这样做,它不起作用 - 在页面加载该行后没有任何操作。 / p>
任何想法为什么?谢谢
解决方案
不幸的是,REQUIRE的HTML规范是一个结束标记...
HTML标准,第18.2.1节< a>
18.2.1 SCRIPT元素
开始标记:必填,结束标记:必填
I'd like to include a javascript file on every page of a site. I can do this with:
<script type="text/javascript" src="myFile.js" ></script>
This works fine - however as there's nothing between the two tags, I wanted to change it to:
<script type="text/javascript" src="myFile.js" />
If I do this, it doesn't work - nothing after that line loads on the page.
Any ideas why? Thanks
解决方案
Unfortunately, the HTML specs for REQUIRE a closing tag...
HTML Standard, section 18.2.1
18.2.1 The SCRIPT element
Start tag: required, End tag: required
这篇关于在HTML中包含JavaScript文件不会像< script .... />的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文