Js取得頁面位址參數
function getUrlPparaName) >{
var sUrl = location.href;
var sReg = "(?://?|&){1}" paraName "=([^&]*)"
var re = new RegExp(sReg, "gi");
re.exec(sUrl);
return RegExp.$1;
}
地址跳轉
var pn = $("#gotopagenum").val();//#gotopagenum是文字方塊的id屬性
location.href = "NewList.aspx?pagenum=" pn;//location.href實作客戶端頁面的跳躍
千分位
function Convert(money)
{
money; //取得小數型資料
s = "";
if (s.indexOf(".") == -1) s = ".00"; //如果沒有小數點,後面補個小數點和00
if (/.d$/.test(s)) s = "0"; //正規判斷
while (/d{4}(.|,)/.test(s )) //符合條件則進行替換
s = s.replace(/(d)(d{3}(.|,))/, "$1,$2"); //每隔3位加一個
return s;
}
判斷是否數字
function IsNumeric(txt) {
if (txt == "") {
return false;
}
if (txt.indexOf( ",") > 0) {
txt = txt.replace(",", "");
}
if (isNaN(txt)) {
return false;
}
else {
return true;
}
}
將數字進行兩位小數的格式化
程式碼如下:
function changeTwoDecimal_f(x) {
var f_x = parseFloat(if); isNaN(f_x)) {
alert('function:changeTwoDecimal->parameter error');
return false;
}
f_x = Math.round(f_x * 100) / 1000) var s_x = f_x.toString();
var pos_decimal = s_x.indexOf('.');
if (pos_decimal pos_decimal = s_x.length;
s_>pos_decimal = s_x.length;
s_>d .';
}
while (s_x.length s_x = '0';
}
return s_x;
}
}
return s_x;
}
}
return s_x;
>
Js 進行數字運算的函數parseFloat parseInt
js 當前日期yyyy-mm-dd 預置查詢條件
複製程式碼
複製程式碼
複製程式碼
複製程式碼
var now = new Date();
var year = now.getYear();
if (now.getYear() year = now.getYear() 1900;
}
var month = now.getMonth() 1;
var day = now.getDate(); >
if (month if (day
$("#txtDate1").val(year .toString() "-" month.toString() "-01");
$("#txtDate2").val(year.toString() "-" month.toString() "-" day.toString ());
Js 取得時間戳,在某些情境下取代Guid
複製程式碼
複製程式碼
複製碼
程式碼如下:
function NowTimeCode()
{
var Result="";
var now = new Date();
var year = now.getYear();
if (now.getYear() year = now.getYear() 1900; } var month = now.getMonth() 1; var day = now.getDate(); var hour = now.getHours(); var minutes = now.getMinutes(); var second = now.getSeconds(); var millisecond = now.getMilliseconds(); if (month if (day if (hour if (minutes if (second if (millisecond millisecond = "00" millisecond; else { if (millisecond {
0" millisecond; } } Result = year.toString() month.toString() day.toString() hour.toString() minutes.toString() second.toString() millisecond.toString(); return Result; }