【发布时间】:2013-04-12 20:57:17
【问题描述】:
刚开始学习Require.js
文件系统是这样的:
这是我的 index.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="lib/require/require.min.js" data-main="lib/main"></script>
</head>
<body>
<span id="content"></span>
</body>
</html>
现在,我知道加载到 DOM 的 第一个 文件是 require.js,然后加载 lib/main.js
现在 main.js 是
require(['jquery'],function($){
//this works since both **main.js** and **jquery.js** are in same folder
$("#content").html("jquery am loaded");
});
现在,如果我将 jquery.js 保存在与 main.js 相同的文件夹中,那么问题就来了,代码可以正常工作,但是如果我将路径更改为 jquery/jquery.js 并更改 main.js。 js作为
require(['jquery/jquery'],function($){
//this thing shows 'Uncaught TypeError: undefined is not a function'
$("#content").html("jquery am loaded");
});
我理解问题在于,如果 jquery.js 位于 main.js 以外的任何其他文件夹中,它不会加载它是,但是为什么,请阐明一下如何实现。
【问题讨论】:
标签: javascript jquery requirejs