javascript - 使用 HTML 同时调用两个 javascript 文件

标签 javascript jquery backbone.js

我有一个 html 文件和两个 .js 文件。我将多个脚本标签放入一个 html 文件中,因为我使用的是 Backbone js。

<html>
   <body>
     <script type="text/x-template" id="my-template">
        some html contents
        <script src="/javascripts/validation.js"></script>
        <script src="/javascripts/other.js"></script>
      </script>
      <script type="text/x-template" id="myfile-template">
        some html contents
      </script>
      <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    </body>
  </html>

我的问题是我无法从 my-template 脚本调用 2 个 js 文件。在上面的代码中,仅调用“validation.js”,如果我将“other.js”放在前面,则仅调用“other.js”。

<script src="/javascripts/other.js"></script>
 <script src="/javascripts/validation.js"></script>

有人可以帮助我吗?

最佳答案

您不能将标签放入其他标签内。

如果您想导入两个 JS 文件,只需执行以下操作:

<!-- Include external JS code -->
<script src="/javascripts/validation.js"></script> 
<script src="/javascripts/other.js"></script> 
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<!-- local JS code -->
<script type="text/x-template" id="my-template">/* some local JS code */</script> 
<script type="text/x-template" id="myfile-template">/* some local JS code */</script> 

关于javascript - 使用 HTML 同时调用两个 javascript 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23513033/

相关文章:

javascript - 使用 Jquery/Javascript 刷新后设置 Selectbox 值?

jquery 表单使用 .on() 提交

javascript - 初始加载后,主干模型在项目 View 中未定义

javascript - toJSON() 和 JSON.Stringify() 之间的区别

javascript - 如何在深度未知的数组内递归构建子数组的路径

javascript - 如何根据屏幕宽度将我的导航栏类更改为另一个导航栏类?

javascript - jQuery val() 在 IE 中无法用于动态添加的选项

javascript - 使用 Javascript/Jquery 搜索 google.com

javascript - 在网页加载之前预加载图像

backbone.js - BACKBONE/JS 最佳实践 : Is it good or bad to initialise a model inside view?