Q1:cmd引入jquery實例1:css
1:js1.jshtml
define(function (require,exports,module) { exports.message="我是被js1所調用的." exports.obj={ select:function () { console.log("你查詢了!"); }, delete:function () { console.log("你刪除了!"); } }; });
2:js2.jsjquery
define(function (require,exports,module) { var js1=require('./js1'); js1.obj.delete();js1.obj.select(); exports.message="我是調用js1的."; exports.show=function () { console.log("我輸出的是js2"); } });
3:app.jsapp
seajs.config({ alias: { "jquery":"./js/jquery/jquery-1.11.3" } }); var js2=seajs.use(['./libs/js2.js','jquery'],function (js2,$) { /*js2.obj.select();js2.obj.delete();*/ console.log(js2.message);js2.show();$("body").css("background","red"); });
4:index.htmlui
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <script src="js/sea.js/sea.js"></script> <script src="app.js"></script> </body> </html>
注意:默認是不支持cmd的,須要改jquery源碼:(ctrl+F 輸入define.amd 找到jquery中的這一行,修改:如圖所示)spa
報錯以下:code
解決以下:htm