[英]Require.js Uncaught TypeError: undefined is not a function
I just started learning Require.js 我刚开始学习Require.js
the file system is like : 文件系统如下:
This is my index.html 这是我的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>
Now, this I knows that the 1st file that loaded on to the DOM is require.js then after that it loads lib/main.js 现在,我知道加载到DOM的第一个文件是require.js然后加载lib / main.js
Now the main.js is 现在main.js是
require(['jquery'],function($){
//this works since both **main.js** and **jquery.js** are in same folder
$("#content").html("jquery am loaded");
});
Now here is the problem if I keep jquery.js in the same folder as that in main.js the code works fine, but if I change the path to jquery/jquery.js and change the main.js as
现在问题是如果我将jquery.js保存在与main.js相同的文件夹中,代码工作正常,但是如果我将路径更改为jquery / jquery.js并将main.js更改为
require(['jquery/jquery'],function($){
//this thing shows 'Uncaught TypeError: undefined is not a function'
$("#content").html("jquery am loaded");
});
I understood the problem is that it is not loading the jquery.js if it is inside any other folder other that main.js is, but why, please shed some light and how that can be achieved. 我明白问题是它没有加载jquery.js,如果它在main.js以外的任何其他文件夹中,但是为什么,请说明一下如何实现。
To use RequireJS and jQuery, you should either use the combined RequireJS/jQuery file, available at: 要使用RequireJS和jQuery,您应该使用组合的RequireJS / jQuery文件,该文件位于:
http://requirejs.org/docs/jquery.html http://requirejs.org/docs/jquery.html
Or use a path
. 或者使用
path
。
http://requirejs.org/docs/api.html#config-paths http://requirejs.org/docs/api.html#config-paths
require.config({
paths: {
"jquery": 'http://code.jquery.com/jquery-1.9.1'
}
});
require(["jquery"], function ($) {
console.log($.fn.jquery);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.