建立一个js模块
layui.define(['form'], function(exports) {
var form = layui.form;
var $ = layui.$;
var btnName = localStorage.getItem("BtnBagcolor");
function changeTheme(btnName,parentDOC) {
if(btnName == "默认") {
$(parentDOC).find("#companyName").attr("style", "background-color:#001529");
}
}
exports('changeTheme',changeTheme);
})
引入模块且使用
html中(要注意js模块必须要在使用它的js之前引入,否则使用的js会报错)
<script src="../../test.js" type="text/javascript" charset="utf-8"></script>
<script src="../../MenuJS.js"></script>
js中
layui.define(['element', 'form', 'layer', 'changeTheme'], function(exports) {
var element = layui.element;
var layer = layui.layer;
var form = layui.form;
var changeTheme = layui.changeTheme;
var $ = layui.$;
var parentDOC = window.document;
var btnName = localStorage.getItem("BtnBagcolor");
changeTheme(btnName,parentDOC)
});