//獲取URL中的request參數 function getUrlParam(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) { return decodeURIComponent(r[2]); } else { return ""; } } //獲取URL中的request參數 function getUrlParamByName(name) { var reg = new RegExp("-(.*?)\.html"); var r = window.location.href.match(reg); var str = ""; if (r != null) { str = decodeURIComponent(r[0]); } str = str.substring(1, str.lastIndexOf(".html")).trim(); if (str == null || str.length <= 0) { str = getUrlParam(name); } return str; } //彈出窗口,無滾動條 function openNoBarWin(url, widths, heights) { var features = "height=" + heights + ", width=" + widths + ", toolbar =yes, menubar=no, scrollbars=no, resizable=yes, location=no, status=no,top=200,left=200"; var w = window.open(url, "newwindow", features); w.focus(); } //彈出窗口,有滾動條 function openNoScroBarWin(url, widths, heights) { var features = "height=" + heights + ", width=" + widths + ", toolbar =yes, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no,top=200,left=200"; var w = window.open(url, "newwindow", features); w.focus(); } //彈出普通IE窗口 function openNormalWin(url, widths, heights) { var features = "height=" + heights + ", width=" + widths + ", toolbar =yes, menubar=yes, scrollbars=yes, resizable=yes, location=yes, status=yes"; var w = window.open(url, "newwindow", features); w.focus(); } function ViewProfile(urid) { openNormalWin("/Web/Profile/index.aspx?userid=" + urid + "&RndCode=" + UrlRndCode, "900", "480"); } //鼠標通過彈出層 function ShowTitleContent(TitleContent) { var event = new Event(event); $("mouseshow").style.display = "block"; $("mouseshow").innerHTML = '<img style="position:absolute; left:-7px; top:5px;" src="/Images/Hqen/tipArrow_blue.gif" alt="" />' + TitleContent; var eImg = $(event.target); $("mouseshow").style.left = ((eImg.getLeft()) + 20) + "px"; $("mouseshow").style.top = ((eImg.getTop()) + 2) + "px"; } function HiddenTitleContent() { $("mouseshow").style.display = "none"; } function getContentHtml() { var str = document.getElementById('Editor').contentWindow.document.getElementById('HtmlEditor').contentWindow.document.getElementsByTagName("BODY")[0].innerHTML; //alert(str); return str; } //把數據庫裏的"\n"替換成<br> function Db2HTML(str) { if (str == null || str == "") return ""; var strtmp = str; // strtmp = strtmp.replace("\n","<br>"); strtmp = (strtmp.replace(new RegExp("\n", "gm"), "<br>")); strtmp = (strtmp.replace(new RegExp(" ", "gm"), " ")); return strtmp; } //把<br>的替換成\n function HTML2Db(str) { if (str == null || str == "") return ""; var strtmp = str; strtmp = (strtmp.replace(new RegExp("<br>", "gm"), "\n")); strtmp = (strtmp.replace(new RegExp(" ", "gm"), " ")); return strtmp; } //去掉先後的空格 function Trim(str) { return str.replace(/(^\s*)|(\s*$)/g, ""); } //去掉左邊的空格 function Ltrim(str) { return str.replace(/(^\s*)/g, ""); } //去掉右邊的空格 function Rtrim(str) { return str.replace(/(\s*$)/g, ""); } //將空字符替換成Null function CheckNull(text) { if (text == null) { return null; } else if (text != null) { text = text.replace(/(^\s*)|(\s*$)/g, ""); if (text == "") { return null; } else { return text; } } } //驗證是否爲整數 function IsNumber(str) { var exp = /[^0-9()-]/g; if (str.search(exp) != -1) { return false; } return true; } //驗證是否爲正整數 function IsPlusNumber(str) { var exp = /[^0-9()]/g; if (str.search(exp) != -1) { return false; } return true; } //乘法函數,用來獲得精確的乘法結果 //說明:javascript的乘法結果會有偏差,在兩個浮點數相乘的時候會比較明顯。這個函數返回較爲精確的乘法結果。 //調用:accMul(arg1,arg2) //返回值:arg1乘以arg2的精確結果 function ConvertMul(arg1, arg2) { var m = 0, s1 = arg1.toString(), s2 = arg2.toString(); try { m += s1.split(".")[1].length; } catch (e) { } try { m += s2.split(".")[1].length; } catch (e) { } return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m); } //加法函數,用來獲得精確的加法結果 //說明:javascript的加法結果會有偏差,在兩個浮點數相加的時候會比較明顯。這個函數返回較爲精確的加法結果。 //調用:accAdd(arg1,arg2) //返回值:arg1加上arg2的精確結果 function ConvertAdd(arg1, arg2) { var r1, r2, m; try { r1 = arg1.toString().split(".")[1].length; } catch (e) { r1 = 0; } try { r2 = arg2.toString().split(".")[1].length; } catch (e) { r2 = 0; } m = Math.pow(10, Math.max(r1, r2)); return (arg1 * m + arg2 * m) / m; } //減法函數,用來獲得精確的減法結果 //說明:javascript的減法結果會有偏差,在兩個浮點數相加的時候會比較明顯。這個函數返回較爲精確的加法結果。 //調用:ConvertSub(arg1,arg2) //返回值:arg1減去arg2的精確結果 function ConvertSub(arg1, arg2) { var r1, r2, m; try { r1 = arg1.toString().split(".")[1].length; } catch (e) { r1 = 0; } try { r2 = arg2.toString().split(".")[1].length; } catch (e) { r2 = 0; } m = Math.pow(10, Math.max(r1, r2)); return (arg1 * m - arg2 * m) / m; } //驗證是否爲金額格式,只精確兩位小數。 function CheckIsMoney(str) { if (str == "" || str == null) { return true; } if (/^[+]?\d*\.{0,1}\d{0,2}$/.test(str)) { return true; } else { return false; } } //驗證是否爲金額格式,只精確一位小數。 function CheckIsDecimalMoney(str) { if (str == "" || str == null) { return true; } if (/^[+]?\d*\.{0,1}\d{0,1}$/.test(str)) { if (str.substr(str.length - 1, 1) == '.') { return false; } return true; } else { return false; } } //獲取字符串的大小,返回字節的大小 function GetStringLength(text) { var codingText = text.replace(/[^\x00-\xff]/g, "**"); return codingText.length; }