如何在RequireJS中使用jQuery 1.6.2

时间:2012-11-28 14:20:38

标签: javascript jquery requirejs

我试图要求jQuery作为依赖项,但是当我尝试这样做时我只会遇到错误。我知道1.6.2已经过时但是我需要它不要打破其他一些代码。它在我使用1.8.2时有效,但我不得不转回旧版本。

  

未捕获TypeError:undefined不是app.js函数:46

     

(匿名函数)main.js:46 context.execCb require.min.js:1603 Module.check   require.min.js:845(匿名函数)require.min.js:1087   (匿名函数)require.min.js:130(匿名函数)
  require.min.js:1130每个require.min.js:58 Module.emit   require.min.js:1129 Module.check require.min.js:899(匿名   function)require.min.js:1087(匿名函数)
  require.min.js:130(匿名函数)require.min.js:每个1130   require.min.js:58 Module.emit require.min.js:1129 Module.check   require.min.js:899 Module.enable require.min.js:1117 Module.init   require.min.js:758 callGetModule require.min.js:1144   context.completeLoad require.min.js:1517 context.onScriptLoad   require.min.js:1624

1 个答案:

答案 0 :(得分:1)

没有任何例子,你如何启动你的东西,所有这些都很难提供帮助。我会给你一个通用的答案,希望它可以帮助你,或者在等待其他答案时让你忙碌。祝你好运。

来自http://www.bennadel.com/blog/2287-Using-jQuery-As-A-Named-Module-In-RequireJS.htm

<!DOCTYPE html>
<html>
<head>
<title>Loading jQuery As A Named Module In RequireJS</title>

<!-- Include the require JS library. -->
<script type="text/javascript" src="./require.js"></script>
<script type="text/javascript">


// Configure the RequireJS paths to use an alias for the
// jQuery library.
require.config({
paths: {
"jquery": "./jquery-1.6.4"
}
});


// Now that we have configured a named alias for the jQuery
// library, let's try to load it using the named module.
require(
[
"jquery"
],
function( $164 ){

// Log the callback parameter.
console.log( "$164.fn.jquery:", $164.fn.jquery );

}
);


</script>
</head>
<body>
<!-- Left intentionally blank. -->
</body>
</html>