JS判空
function checkData(StackEmpty){if(StackEmpty == null || StackEmpty=="null" || typeof(StackEmpty)=="undefined" || StackEmpty=="undefined" || StackEmpty=="" ){
return false ;//爲null,返回false
}
if(!isNaN(StackEmpty) && StackEmpty!="null" && typeof(StackEmpty)!="undefined" && StackEmpty!="undefined"&& StackEmpty!="" ){
return true ;//不爲null,返回true
}
}
JS定時循環
t=setTimeout('getAlarm()',100000);
//調用本身實現方法循環
var setIntervalValue = setInterval('energyallTable()',5000);
//定時每多少秒執行函數
JS判斷瀏覽器
var dateLong = date.getTime();
//時間戳轉換成Date
var dateDate = new Date(dateLong);
//String 轉dare
var str = "2010-03-22";
var val = Date.parse(str);
var newDate = new Date(val);;
var sNum = num + '';
var idx = sNum.indexOf(".");
if (idx < 0)
return num;
var n = sNum.length - idx - 1;
if (dec < n) {
var e = Math.pow(10, dec);
return Math.round(num * e) / e;
} else {
return num;
}
}
或者是s 四捨五入函數 toFixed(),裏面的參數 就是保留小數的位數。