common.js
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//设置当前页面导航栏背景色
function addTabs(id) {
$('.layui-nav-item').removeClass('layui-this')
$(id).addClass('layui-this')
}
//设置ajax调取服务接口
function SetServicesPath() {
return "http://192.168.2.108"
}
//设置全局參數
var portal =
{
'api_url': "http://192.168.2.108:8000", //属性名用引号括起来,属性间由逗号隔开
'name': 'myName',
"rootPath": GetRootPath()
};
//截取日期
function CutDate(times) {
var timearr = times.replace(" ", ":").replace(/\:/g, "-").split("-");
var timestr = "" + timearr[0] + "/" + timearr[1] + "/" + timearr[2]
//var timestr = "" + timearr[1].split("")[1] + "月" + timearr[2] + "日\t" + timearr[3] + ":" + timearr[4] + ""
return timestr
}
function GetRootPath() {
var curWwwPath = window.document.location.href;
var pathName = window.document.location.pathname;
var pos = curWwwPath.indexOf(pathName);
return curWwwPath.substring(0, pos);
}
function GetQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return (r[2]); return null;
}
// 存储cookie
function setCookie(name, resdata, duration) {
var date = new Date();
date.setTime(date.getTime() + duration * 24 * 3600 * 1000);
document.cookie = name + "=" + JSON.stringify(resdata) + ";expires=" + date.toGMTString() + "; path=/";
// document.cookie = "myCookie=" + JSON.stringify(resdata) + "; expires=" +date.toGMTString() + "; path=/";
};
//获取cookie
function getCookie() {
var str = document.cookie;
if (str == '') {
return false
} else {
var arr = str.split(';')
var arr1 = arr[0].replace(/(\s)+/g, '').split('=');
return JSON.parse(arr1[1]);
}
};
/*
* 验证手机号码
*/
function validatorTel(content) {
// 正则验证格式
eval("var reg = /^1[34578]\\d{9}$/;");
return RegExp(reg).test(content);
}