//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")