//name:参数名 function GetQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i"); var r = window.location.search.substr(1).match(reg); if (r!=null) return unescape(r[2]); return null; } //替换URL指定参参数 /* * url 目标url * arg 须要替换的参数名称 * arg_val 替换后的参数的值 * return url 参数替换后的url */ function changeURLArg(url,arg,arg_val){ var pattern=arg+'=([^&]*)'; var replaceText=arg+'='+arg_val; if(url.match(pattern)){ var tmp='/('+ arg+'=)([^&]*)/gi'; tmp=url.replace(eval(tmp),replaceText); return tmp; }else{ if(url.match('[\?]')){ return url+'&'+replaceText; }else{ return url+'?'+replaceText; } } return url+'\n'+arg+'\n'+arg_val; } //判断该文本域动态输入的字符数 jsp页面文本域中onkeyup="inMaxLength(this);" function inMaxLength(obj){ //最大字数 var maxLength=100; //当前字数 var length = $(obj).val().length; //剩余字数 var left=maxLength-length; if (length>=maxLength) { var newValue=$(obj).val().substring(0,maxLength); $(obj).val(newValue); left=0; } //显示还剩多少字的div的id $("#maxlength").html(left); return true; }
//万能的首页、尾页链接变灰的方法 //obj:元素 //disable:true/false function disableAnchor(obj, disable){ debugger; if(disable){ var href = obj.getAttribute("href"); if(href && href != "" && href != null){ obj.setAttribute('href_bak', href); } obj.removeAttribute('href'); obj.style.color="gray"; }else{ obj.setAttribute('href', obj.attributes['href_bak'].nodeValue); obj.style.color="blue"; } } ///计算两个整数的百分比值 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 + "%"); }
//js字符串转为数字想加 parseInt("a")+parseInt("b")
//若是不知道从后台传来的对象是什么类型, 好比Map,在Json显示也是Obejct,那么能够经过获取属性的方式取值 好比数组,获取对应数组的值 for(prop in result){ console.log(prop); }
var arr = new Array();//建立数组 arr.push(object);//加入对象 arr.join(str);//加入字符串
//指定时间格式 function formatDate(date, format) { if (!date) return; if (!format) format = "yyyy-MM-dd"; switch(typeof date) { case "string": date = new Date(date.replace(/-/, "/")); break; case "number": date = new Date(date); break; } if (!date instanceof Date) return; var dict = { "yyyy": date.getFullYear(), "M": date.getMonth() + 1, "d": date.getDate(), "H": date.getHours(), "m": date.getMinutes(), "s": date.getSeconds(), "MM": ("" + (date.getMonth() + 101)).substr(1), "dd": ("" + (date.getDate() + 100)).substr(1), "HH": ("" + (date.getHours() + 100)).substr(1), "mm": ("" + (date.getMinutes() + 100)).substr(1), "ss": ("" + (date.getSeconds() + 100)).substr(1) }; return format.replace(/(yyyy|MM?|dd?|HH?|ss?|mm?)/g, function() { return dict[arguments[0]]; }); }
//获取系统当前时间 function getNowFormatDate() { var date = new Date(); var seperator1 = "-"; var seperator2 = ":"; var month = date.getMonth() + 1; var strDate = date.getDate(); if (month >= 1 && month <= 9) { month = "0" + month; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + date.getHours() + seperator2 + date.getMinutes() + seperator2 + date.getSeconds(); return currentdate; }
formatDate(getNowFormatDate(),"yyyy-MM-dd HH:mm:ss")