aganliang 2020-02-02
index.html:引入require.js
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Document</title> </head> <body&g 大专栏 RequireJS(一)t; <script src="js/require.js" data-main="js/main"></script> </body> </html>
main.js:引入jquery,validate.js定义别名
requirejs.config({ paths:{ jquery:'jquery-1.11.1' } }); //传入引入模块 requirejs(['jquery','validate'],function($,validate){ console.log(validate.isEqual(1,2)) });
validate.js:define定义模块
define(['jquery'],function($){ //需要引入模块,此处并没有使用引入的jqury模块 return { isEmpty:function(){}, checkLength:function(){}, isEqual:function(str1,str2){ return str1=== str2; } } });