<script src="../static/js/lib/require.js" data-main="../static/js/script/main" id="moudle" moudle-name ="login" defer async="true" ></script>
以上为页面中引入requirejs内容
require.config({
baseUrl:"https://test.com",
paths:{
"jquery":"/static/js/lib/jquery",
"cookie":"/static/js/lib/jquery.cookie",
"pc_pop":"/static/js/lib/pc_pop",
"popWindow":"/static/js/lib/popWindow",
"layer":"/static/js/lib/layer/layer",
"examservice":"/static/js/script/examservice",
"commonjs":"/static/js/script/commonjs",
"login":"/static/js/script/login",
"infoSure":"/static/js/script/infoSure",
"sign":"/static/js/script/sign",
"agreement":"/static/js/script/agreement",
"exam":"/static/js/script/exam"
},
shim:{
}
});
/**
* 不同页面回调执行不同内容
*/
require(["jquery"], function ($) {
var moudleName = $("#moudle").attr("moudle-name");
if (moudleName) {
$(function () {
require([moudleName], function (objRQ) {
switch (moudleName) {
case 'login':
objRQ.login.fieldArr = ["ticketNum"];
objRQ.login.eleObj.loginBtn = "loginBtn";
objRQ.login.eleObj.testCameraBtn = "testCamera";
objRQ.login._init(sessionStorage.getItem("matchId"));//表单用户信息
break;
case 'infoSure':
objRQ.infoSure._init();
break;
case 'sign':
objRQ.sign._init();
break;
case 'agreement':
objRQ.examAgreement._init(sessionStorage.getItem("matchId"),{
beginBtn:"startBtn",//开始考试按钮,默认是disabled
agreementBtn:"agreementBtn",
HH:"HH",//显示倒计时的小时span
MM:"MM",//显示倒计时的分钟span
SS:"SS"//显示倒计时的秒span
});
break;
case 'exam':
objRQ.exam.maxRandom = 2;
objRQ.exam._init(12);
break;
}
});
});
return;
}
});
以上为入口main.js中动态获取script标签id属性,然后根据不同模块初始化不同内容