问题描述
我最近才开始使用jQuery&开发了一个小应用程序.但是由于大量的JavaScript代码,页面大小正在增加,因此我开始将代码移到单独的脚本文件中.但是,
1)当我将代码移到单独的js文件时,因为它们位于其他脚本文件中,所以我无法访问其他jquery插件函数.如何在单独的脚本文件中使用其他库?
2)我做错了吗?这在我单独的脚本文件(foo.js)中根本不起作用.它说stringify不是函数
I just started using jquery lately & developed a small application. However the pagesize was increasing because of a lot of javascript code so I am starting to move the code in separate script files. However,
1) I cannot access other jquery plugins functions when I move my code to separate js file because they are located in other script files. How do I use the other libraries in my separate script file ?
2) Am I doing it the wrong way ? This does not work at all in my separate script file (foo.js). It says stringify is not a function
<script src="../assets/scripts/jquery.json-2.2.min.js" type="text/javascript">
</script>
$(document).ready(function(){
JSON.stringify(''test message'');
});
推荐答案
<script src="../assets/scripts/jquery.json-2.2.min.js" type="text/javascript">
</script>
但更可能是这样:
but more likely this:
<script src="assets/scripts/jquery.json-2.2.min.js" type="text/javascript">
</script>
但是如果没有更多信息,我将无法确定100%.
but I can''t be 100% sure without further information.
/// <reference path="../assets/scripts/jquery.json-2.2.min.js" />
请按照下面的讨论
http://www.eggheadcafe.com/community/aspnet/3/10131184/how-to-add-javacript-file-reference-in-another-javascript-file.aspx [ ^ ]
希望这会有所帮助.
follow the discussion below
http://www.eggheadcafe.com/community/aspnet/3/10131184/how-to-add-javacript-file-reference-in-another-javascript-file.aspx[^]
hope this will help.
这篇关于Javascript代码组织的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!