Files
system-jibei/pqs9000/src/main/webapp/jspJS/utils/common.js
2024-04-01 09:20:31 +08:00

77 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 获取url参数
* @param name 参数名
* @returns 值
*/
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var result = window.location.search.substr(1).match(reg);
return result ? decodeURIComponent(result[2]) : '';
}
/**
* 格式化时间需要Date类型
* @param name 参数名
* @returns 值
*/
function formatTime(data,type) {
if (data == null) {
return '/';
} else {
var date = new Date(data);
var y = date.getFullYear();// 年
var MM = date.getMonth() + 1;// 月
MM = MM < 10 ? ('0' + MM) : MM;
var c = date.getDate();// 日
c = c < 10 ? ('0' + c) : c;
var h = date.getHours();// 时
h = h < 10 ? ('0' + h) : h;
var m = date.getMinutes();// 分
m = m < 10 ? ('0' + m) : m;
var s = date.getSeconds();// 秒
s = s < 10 ? ('0' + s) : s;
}
if(type == 1){
//精确到秒
return y + '-' + MM + '-' + c + ' ' + h + ':' + m + ':' + s;
}else {
return y + '-' + MM + '-' + c;
}
}
//验证输入框输入长度
function valiteLength(value) {
var i,sum;
sum=0;
for(i=0;i<value.length;i++){
if ((value.charCodeAt(i)>=0) && (value.charCodeAt(i)<=64))
sum=sum+1;
else
sum=sum+2;
}
if (sum > 64) {
return '最多只能64个字符或者32个中文字';
}else {
return ''
}
}
/**
* 获取当前年月
*/
function getNowDate() {
var myDate = new Date();
var tYear = myDate.getFullYear();
var tMonth = myDate.getMonth();
var m = tMonth + 1;
if (m.toString().length == 1) {
m = "0" + m;
}
return tYear+"-"+m
}