公共文件模块include

本文介绍了一种通过在前端页面中集中引入CSS样式表和JavaScript文件的方法。通过定义一个获取项目基本URL的函数,并利用该URL来加载所需的资源文件,可以有效地简化页面加载过程并提高网站的可维护性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先新建一个include

把所有引入的文件放入公共文件里

function getBaseURL() {
var pathName = window.document.location.pathname;
var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
return location.protocol + "//" + location.hostname +
(location.port && ":" + location.port) + projectName + "/";
}

var httpUrl = getBaseURL(); // 公网服务器请求地址

var baseUrl = getBaseURL();

// CSS
document.write('<link rel="stylesheet" href="' + baseUrl + 'resources/awesome/css/font-awesome.min.css">');
document.write('<link rel="stylesheet" href="' + baseUrl + 'resources/bootstrap/css/bootstrap.css">');
document.write('<link rel="stylesheet" href="' + baseUrl + 'resources/bootstrap/css/bootstrap-table.css">');
document.write('<link rel="stylesheet" href="' + baseUrl + 'resources/bootstrap/css/bootstrap-dialog.css">');
document.write('<link rel="stylesheet" href="' + baseUrl + 'resources/toastr/toastr.min.css">');
document.write('<link rel="stylesheet" href="' + baseUrl + 'resources/select2/select2.min.css">');
document.write('<link rel="stylesheet" href="' + baseUrl + 'resources/bootstrap-treeview/bootstrap-treeview.css">');
document.write('<link rel="stylesheet" href="' + baseUrl + 'resources/jquery/css/jquery.datetimepicker.css">');
document.write('<link rel="stylesheet" href="' + baseUrl + 'module/common/utstyle.css">');
document.write('<link rel="stylesheet" href="' + baseUrl + 'module/common/style.css">');

// JS
document.write('<script type="text/javascript" src="' + baseUrl + 'resources/jquery/jquery-1.11.3.js"></script>');
document.write('<script type="text/javascript" src="' + baseUrl + 'resources/jquery/underscore.js"></script>');
document.write('<script type="text/javascript" src="' + baseUrl + 'resources/bootstrap/js/bootstrap.min.js"></script>');
document.write('<script type="text/javascript" src="' + baseUrl + 'module/common/page-jdmc.js"></script>');
document.write('<script type="text/javascript" src="' + baseUrl + 'module/common/constant.js"></script>');
document.write('<script type="text/javascript" src="' + baseUrl + 'resources/bootstrap-table/js/bootstrap-table.js"></script>');
document.write('<script type="text/javascript" src="' + baseUrl + 'resources/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>');
document.write('<script type="text/javascript" src="' + baseUrl + 'resources/bootstrap/js/bootstrap-dialog.min.js"></script>');
document.write('<script type="text/javascript" src="' + baseUrl + 'resources/jquery/jquery.validate.min.js"></script>');
document.write('<script type="text/javascript" src="' + baseUrl + 'resources/toastr/toastr.min.js"></script>');

// select2插件
document.write('<script type="text/javascript" src="' + baseUrl + 'resources/select2/select2.min.js"></script>');
document.write('<script type="text/javascript" src="' + baseUrl + 'resources/select2/i18n/zh-CN.js"></script>');
document.write('<link rel="stylesheet" href="' + baseUrl + 'resources/jquery/jquery.editable-select.min.css">');
document.write('<script type="text/javascript" src="' + baseUrl + 'resources/jquery/jquery.editable-select.min.js"></script>');

document.write('<script type="text/javascript" src="' + baseUrl + 'resources/bootstrap-treeview/bootstrap-treeview.js"></script>');

document.write('<script type="text/javascript" src="' + baseUrl + 'resources/bootstrapValidator/js/bootstrapValidator.min.js"></script>');

// 滚动条修改
document.write('<link rel="stylesheet" href="' + baseUrl + 'resources/mCustomScrollbar/css/jquery.mCustomScrollbar.css">');
document.write('<script type="text/javascript" src="' + baseUrl + 'resources/mCustomScrollbar/jquery.mousewheel.min.js"></script>');
document.write('<script type="text/javascript" src="' + baseUrl + 'resources/mCustomScrollbar/jquery.mCustomScrollbar.min.js"></script>');


// 时间控件
document.write('<script type="text/javascript" src="' + baseUrl + 'resources/jquery/jquery.datetimepicker.full.min.js"></script>');

// 视频播放
document.write('<link rel="stylesheet" href="' + baseUrl + 'resources/video-player/mediaelementplayer.css">');
document.write('<script type="text/javascript" src="' + baseUrl + 'resources/video-player/mediaelement-and-player.min.js"></script>');
document.write('<script type="text/javascript" src="' + baseUrl + 'resources/video-player/lang/zh-cn.js"></script>')


//layer
document.write('<script type="text/javascript" src="' + baseUrl + 'resources/layer/layer.js"></script>');
// backbone.js
document.write('<script type="text/javascript" src="' + baseUrl + 'resources/jquery/backbone.js"></script>');
// vue.js
document.write('<script type="text/javascript" src="' + baseUrl + 'resources/vue/vue.min.js"></script>')


// 公用js
document.write('<script type="text/javascript" src="' + baseUrl + 'module/common/tool.js"></script>');

转载于:https://www.cnblogs.com/benmumu/p/9378478.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值