4
我刚开始学习Require.jsRequire.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更改为
require(['jquery/jquery'],function($){
//this thing shows 'Uncaught TypeError: undefined is not a function'
$("#content").html("jquery am loaded");
});
我理解的问题是,它不加载的jquery.js如果是其他的任何其他文件夹里面那个main.js是,但为什么,请提供一些线索,以及如何能取得成就。
最近,我用你的代码,看到jQuery的文件加载在**网络督察**,但我仍然感到困惑,为什么** ** require.js不推参数在** $ **的回调中。 –
不推送$参数的回调? –
require(['jquery/jquery'],function($){//这里$是推送或放置的jquery内容的参数, jquery am loaded“); }); –