我有一个 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/