简体   繁体   English

Require.js Uncaught TypeError:undefined不是函数

[英]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.

相关问题 未捕获的TypeError:使用require.js时undefined不是函数 - Uncaught TypeError: undefined is not a function when using require.js Require.js未被捕获的TypeError:jqOAuth不是一个函数 - Require.js Uncaught TypeError: jqOAuth is not a function Require.js:未捕获的TypeError:对象函数…没有方法 - Require.js : Uncaught TypeError: Object function … has no method require.js未捕获的TypeError:对象的属性&#39;$&#39; <Object> 不是一个功能 - require.js Uncaught TypeError: Property '$' of object #<Object> is not a function require.js uncaught typeerror:无法读取属性&#39;__module_path__; 未定义的 - require.js uncaught typeerror: cannot read property '__module_path__; of undefined require.js和bone.js获取未捕获的TypeError - require.js and backbone.js getting Uncaught TypeError Require.js / Jquery Datable:未定义不是函数 - Require.js/Jquery Datable : undefined is not a function Require.js + TypeError:优化后未定义Backbone - Require.js + TypeError: Backbone is undefined after optimization Backbone.js和Require.js-未捕获的TypeError:对象函数(){return parent.apply(this,arguments); }没有方法“开” - Backbone.js and Require.js - Uncaught TypeError: Object function (){ return parent.apply(this, arguments); } has no method 'on' Require.js和Imager.js未定义函数 - Require.js and Imager.js undefined function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM