📄 common.js
字号:
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr;
for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++){
if(x.flag==null || x.flag == false){
x.src=x.oSrc;
}
}
}
function MM_preloadImages() { //v3.0
var d=document;
if(d.images){
if(!d.MM_p) {
d.MM_p=new Array();
}
var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
for(i=0; i<a.length; i++) {
if (a[i].indexOf("#")!=0){
d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
}
}
}
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//format the number by special precision
function dataFormat(col_value,precision){
if(precision<0){
precision=0;
}
var addvalue = 5* Math.pow(10,-1*(precision+1));
if(col_value>0){
var value=col_value*1+addvalue;
}else{
var value=col_value*1-addvalue;
}
var value_str=value+"";
var pointIndex=value_str.indexOf(".");
if(precision==0){
pointIndex--;
}
var toIndex=pointIndex+precision*1+1;
if(toIndex>=value_str.length){
toIndex=value_str.length-1;
}
value_str_final=value_str.substr(0,toIndex);
/*while(value_str_final.lastIndexOf("0")==value_str_final.length-1){
value_str_final=value_str_final.substr(0,value_str_final.length-1);
}*/
while(value_str_final.lastIndexOf(".")==value_str_final.length-1){
value_str_final=value_str_final.substr(0,value_str_final.length-1);
}
if(value_str_final*1==0 && value_str_final.charAt(0)=="-"){
value_str_final=value_str_final.substr(1,value_str_final.length);
}
return value_str_final;
}
//make the status of cursor to wait
function setCursorWait(){
for(var i=0;i<document.all.length;i++){
document.all[i].org_cursor = document.all[i].style.cursor;
document.all[i].style.cursor="wait";
}
}
//resume the status of cursor with the appointed window
function waitEnd(obj){
for(var i=0;i<obj.document.all.length;i++){
if(obj.document.all[i].org_cursor!=null){
obj.document.all[i].style.cursor=obj.document.all[i].org_cursor;
}
}
}
//set the wait hint, when loading page
var timeout = 0, waitTime = 0;
var nWinObj, nDocObj;
function setWaitHint(winObj, docObj){
var stat = docObj.document.readyState;
nWinObj = winObj;
nDocObj = docObj;
if (stat == "complete"){
clearTimeout(timeout);
winObj.document.all.waitHint.style.display = "none";
waitEnd(winObj);
docObj.style.display = "";
}
else{
//waitTime = waitTime + 0.1;
//winObj.document.all.waitTimeHint.innerHTML = "" + dataFormat(waitTime, 1) ;
timeout = setTimeout("setWaitHint(nWinObj, nDocObj)", 100);
}
}
/*
* add the item of select
* available
* selected
* delAlert
*/
function addItem(available, selected, addAlert){
var i;
if (available.selectedIndex >= 0) {
for (i = 0; i < available.length; i++) {
if (available.options[i].selected) {
var ooption = document.createElement("option");
ooption.text = available[i].text;
ooption.value = available[i].value;
selected.add (ooption, selected.length);
}
}
for (i = available.length - 1; i >= 0; i--) {
if (available.options[i].selected) {
available.remove(i)
}
}
}
else {
if (available.length > 0) {
alert(addAlert);
available.focus();
}
}
if(available.length > 0) {
available.focus();
available[0].selected = true;
}
}
/*
* delete item of select
* available
* selected
* delAlert
*/
function delItem(available, selected, delAlert){
var i;
if (selected.selectedIndex >= 0) {
for (i = 0; i < selected.length; i++) {
if (selected.options[i].selected) {
var ooption = document.createElement("option");
ooption.text = selected[i].text;
ooption.value = selected[i].value;
available.add (ooption, available.length);
}
}
for (i = selected.length - 1; i >= 0; i--) {
if (selected.options[i].selected) {
selected.remove(i)
}
}
}
else {
if (selected.length > 0) {
alert(delAlert);
selected.focus();
}
}
if (selected.length > 0) {
selected.focus();
selected[0].selected = true;
}
}
/*
* drop the ege blank character of a string
* sData String
*/
function trim(sData) {
while ((sData.length > 0) && (( sData.charAt(0)==' ') ||( sData.charAt(0)=='\t'))){
sData=sData.substring(1,sData.length);
}
while ((sData.length > 0) && (( sData.charAt(sData.length-1)==' ')
|| sData.charAt(sData.length-1)=='\t')){
sData=sData.substring(0,sData.length-1);
}
return sData;
}
/** replace content of a string with special string */
function replace(strSource, strFrom, strTo) {
if(strSource == null || strFrom == null || strTo == null){
return strSource;
}
var strDest = "";
var intFromLen = strFrom.length;
var intPos;
while ((intPos = strSource.indexOf(strFrom)) != -1) {
strDest = strDest + strSource.substring(0, intPos);
strDest = strDest + strTo;
strSource = strSource.substring(intPos + intFromLen);
}
strDest = strDest + strSource;
return strDest;
}
/*
* pop modal dialog
* url
* width
* height
* scrollable
*/
function openModalDialog(url, width, height, scrollable){
var strFeatures = "dialogWidth:" + width + "px;"+"dialogHeight:" + height + "px;";
strFeatures += "center:yes;help:no;resizeable:yes;status:no;scroll:";
if(scrollable != null && "" != scrollable){
strFeatures = strFeatures + scrollable;
} else{
strFeatures = strFeatures + "no";
}
window.showModalDialog(url, window, strFeatures);
}
/*
* judge the order of two date strings
* if beginDate is before endDate then return true, else return false
*
* beginDate
* endDate
*/
function isBefore(beginDate, endDate){
var flag = false;
var beginDateObj = parseDate(beginDate);
var endDateObj = parseDate(endDate);
if(beginDateObj != null && endDateObj != null){
if(beginDateObj.getTime() < endDateObj.getTime()){
flag = true;
}
}
return flag;
}
/*
* judge the order of two date strings
* if beginDate is before endDate then return true, else return false and hint alert
*
* beginDate
* endDate
* alertWords
*/
function isBeforeWithHint(beginDate, endDate, alertWords){
var flag = isBefore(beginDate, endDate);
if(flag == false){
alert(alertWords);
}
return flag;
}
/*
* parse date string, convert to date object with format yyyy-MM-dd
*/
function parseDate(dateStr){
var datePat=/^(\d{2}|\d{4})(\-)(\d{1,2})(\-)(\d{1,2})$/;
var matchArray = dateStr.match(datePat);
if (matchArray == null){
return null;
}
year = matchArray[1];
month = matchArray[3];
day = matchArray[5];
if (year.length!=4 || month.length!=2 || day.length!=2){
return null;
}
return new Date(year, month, day);
}
/*
* 格式化货币数据
*
* 参数:
* currencyCode 货币符号
* money 金额
*
* 返回:格式化后的字符串
*/
function formatCurrency(currencyCode, money) {
var retStr = currencyCode;
if (isNaN(money) || money == 0) {
retStr += "0.00";
}
else {
if (money < 0) {
retStr += " -";
money = - money;
}
// 整数部分
var n = Math.floor(money);
var strN = "" + n;
// 小数部分
var m = Math.round((money - Math.floor(money)) * 100);
var mod = strN.length % 3 - 1;
if (mod < 0) mod += 3;
for (var i = 0; i < strN.length; i++) {
retStr += strN.charAt(i);
if (i % 3 == mod && i != strN.length - 1) {
retStr += ",";
}
}
retStr += ".";
if (m > 0) {
if (m > 9) {
retStr += m;
}
else {
retStr += "0";
retStr += m;
}
}
else {
retStr += "00";
}
}
return retStr;
}
/*
*单元格变色
*/
function changeto(highlightcolor){
source = event.srcElement;
if (source.tagName == "TABLE"){
return;
}
while(source.tagName != "TR"){
source = source.parentElement;
}
if (source.style.backgroundColor != highlightcolor&&source.id != "ignore"){
source.style.backgroundColor = highlightcolor;
}
}
/*
*多选(传入多选框的Id和被选框的Id)
*/
function multiSelect(objId1,objId2){
var obj = eval('document.all.' + objId1);
if(typeof(obj) != "undefined"){
if(obj.length != null){
for(var i = 0;i<obj.length;i++){
obj[i].checked = eval('document.all.' + objId2).checked;
}
}
else{
obj.checked = eval('document.all.' + objId2).checked;
}
}
}
/*
* table_ID : the table ID
* batchCheck_ID : batchCheck_ID
* 全选时使整个表格变色
*/
function changeTableColor(table_ID,batchCheck_ID){
var color = "#EDEDEC";
var obj = eval("document.all." + table_ID);
var batchCheck = eval("document.all." + batchCheck_ID);
var childArrays = obj.rows;
if(batchCheck.checked){
color = "#BFCAD9";
}
for(var i = 1;i<childArrays.length;i++){
childArrays[i].style.backgroundColor = color;
}
}
/**
* Checks dateTime (YYYY-MM-dd HH:mm)
*
* strValue : The string validation is being performed on.
*
* return : true if valid, false if invalid.
*/
function isValidateDateTime( strValue ) {
var objRegExp = /^(\d{4})\-(\d{2})\-(\d{2}) (\d{2}):(\d{2})$/;
var isValid = false;
if(!objRegExp.test(strValue)){
isValid = false;
} else{
var intYear = parseInt(strValue.substring(0, 4),10);
var intMonth = parseInt(strValue.substring(5, 7),10);
var intDay = parseInt(strValue.substring(8, 10),10);
var intHour = parseInt(strValue.substring(11, 13),10);
var intMinute = parseInt(strValue.substring(14, strValue.length),10);
isValid = isValidDate(intDay, intMonth, intYear);
if(intHour > 23 || intHour < 0){
isValid = false;
}
if(intMinute > 59 || intMinute < 0){
isValid = false;
}
}
return isValid;
}
/**
* Checks date
*
* day : day of the date
* month : month of the date
* year : year of the date
*
* return : true if valid, false if invalid.
*/
function isValidDate(day, month, year) {
if (month < 1 || month > 12) {
return false;
}
if (day < 1 || day > 31) {
return false;
}
if ((month == 4 || month == 6 || month == 9 || month == 11) &&
(day == 31)) {
return false;
}
if (month == 2) {
var leap = (year % 4 == 0 &&
(year % 100 != 0 || year % 400 == 0));
if (day>29 || (day == 29 && !leap)) {
return false;
}
}
return true;
}
/*
*
*check the date (format YYYY-MM-dd)
*
*/
function isValidShortDate(dateValue){
var re = /^(\d{4})\-(\d{2})\-(\d{2})$/;
if(!re.test(dateValue)){
return false;
}
var index = dateValue.indexOf("-");
var lastIndex = dateValue.lastIndexOf("-");
var year = dateValue.substring(0,index);
var month = dateValue.substring(index + 1,lastIndex);
var day = dateValue.substring(lastIndex + 1);
return isValidDate(day,month,year);
}
/*
* invalid input if not number
*/
function validNumberText(){
if (!(((window.event.keyCode >= 48) && (window.event.keyCode <= 57)) ||
(window.event.keyCode == 13) ||
(window.event.keyCode == 46) ||
(window.event.keyCode == 45))){
window.event.keyCode = 0 ;
}
}
/*
* 格式化货币数据
*
* 参数:
* currencyCode 货币符号
* money 金额
*
*/
function onKeyPressInNumFld(isDecimal, allowNegative) {
if (isDecimal == null) isDecimal = true;
if (allowNegative == null) allowNegative = true;
if (!((event.keyCode > 47 && event.keyCode < 58)
|| event.keyCode == 13
|| (event.keyCode == 45 && allowNegative)
|| (event.keyCode == 46 && isDecimal))) {
event.returnValue = false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -