1、字符处理
function isNumber(val) {
var regPos = /^\d+(\.\d+)?$/;
var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/;
if(regPos.test(val) || regNeg.test(val)) {
return true;
} else {
return false;
}
}
function isUndefined(A) {
if (A == undefined) {
return 0
} else {
return A
}
}
function delHTML(A) {
if (A === undefined) {
return 0
} else {
return A.replace(/<[^>]+>/g, "");
}
}
function isNull(A) {
if (!A) {
return ""
} else if(A=='null' || A=='Null' ){
return ""
}else {
return A
}
}
function jie(A,B){
if (!A) {
return ""
} else {
if (A.length > B) {
return A.substr(0, B);
} else {
return A
}
}
}
function myTime(A){
if (!A) {
return "";
}
if (A.indexOf("T")>0) {
var arr=A.replace("T"," ");
return arr;
} else {
return A;
}
}
function isEmpty(str) {
if(typeof str== null || str== "" || str== "undefined") {
return true;
} else {
return false;
}
}
2、时间处理
var nowTime=getFormatDate();
function getFormatDate(){
var nowDate = new Date();
var year = nowDate.getFullYear();
var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
var date = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
var hour = nowDate.getHours()< 10 ? "0" + nowDate.getHours() : nowDate.getHours();
var minute = nowDate.getMinutes()< 10 ? "0" + nowDate.getMinutes() : nowDate.getMinutes();
var second = nowDate.getSeconds()< 10 ? "0" + nowDate.getSeconds() : nowDate.getSeconds();
return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second;
}
var start_date= new Date(new Date() - 7 * 24 * 60 * 60 * 1000);
var end_date=new Date();
var startTime = start_date.getFullYear() + p(start_date.getMonth() + 1) + p(start_date.getDate());
var endTime = end_date.getFullYear() + p(end_date.getMonth() + 1) + p(end_date.getDate());
$("#startTime").val(startTime);
$("#endTime").val(endTime);
3、js获取两个数百分比
function GetPercent(num, total) {
num = parseFloat(num);
total = parseFloat(total);
if (isNaN(num) || isNaN(total)) {
return "-";
}
return total <= 0 ? "0%" : (Math.round(num / total * 10000) / 100.00)+"%";
}