< script />之间的区别和< script>< / script>用于在HTML中导入多个js文件 [英] Difference between <script /> and <script></script> for importing multiple js file in HTML

查看:134
本文介绍了< script />之间的区别和< script>< / script>用于在HTML中导入多个js文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近遇到的这个问题,我试图在我的HTML页面中导入多个js文件 -

This issue I recently faced, I was trying to import multiple js files in my HTML page like this -

<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore.js" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js" />
<script src="lib/js/backbone.js" />

但是我面对的问题是,它只加载第一个js文件,其余的js文件没有被加载。我也在浏览器中检查了网络部分,剩下的两个文件只是没有被调用。然后我改变了语法 -

But the issue I was facing is, it was loading only the first js file and the rest of the js file was not getting loaded. I also checked the network section in the browser, the remaining two file was just not getting called. Then I changed the syntax to this -

<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
<script src="lib/js/backbone.js"></script>

然后所有3个文件的加载成功发生。我的问题是,是

And then the loading of all the 3 files happened successfully. My question is, is

<script src="" /> 

错误的语法或者这个问题只针对我?

a wrong syntax or is this issue only specific to me?

推荐答案

脚本标签需要起始标签和结束标签。 来自MDN

Script tag requires both the starting and ending tag. From MDN:


标记遗漏:无,起始标记和结束标记都是必填项。

Tag omission: None, both the starting and ending tag are mandatory.

这篇关于&lt; script /&gt;之间的区别和&lt; script&gt;&lt; / script&gt;用于在HTML中导入多个js文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆