⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utils.js

📁 网站全台:游客浏览图书
💻 JS
字号:

/**
*字符串是否为空或全是空格
*/
function isBlank(str){
	for(i=0;i<str.length;i++)
		if(str.charAt(i)!=" ") return false;
	return true;
}


/**
*字符串是否全为英文字母
*/
function isAllChar(str){
	for(i=0;i<str.length;i++)
		if((str.charAt(i)<'A'||str.charAt(i)>'z')&&(str.charAt(i)<'0'||str.charAt(i)>'9')) {alert(str.charAt(i));return false;
}
	return true;
}

/**
*字符串是否全为数字
*/
function isAllNum(str){
	for(i=0;i<str.length;i++)
		if(str.charAt(i)<'0'||str.charAt(i)>'9') return false;
	return true;
}

/**
*字符串是否为数值格式
*/
function isNum(str){
	for(i=0;i<str.length;i++)
		if((str.charAt(i)<'0'||str.charAt(i)>'9')&&str.charAt(i)!='.') return false;
	return true;
}

/**
*字符串是否为货币格式
*/
function isCurrency(str){
	var offset;
	var afterpoint;
	if(!isNum(str)) return false;
	if((offset = str.indexOf(".")) == -1) return true;
	afterpoint = str.substring(offset + 1);
	if(str.substring(offset + 1).length > 2) return false;
	return true;
}

/**
*弹出窗口
*/
function openwin(url,w,h){
    l = (screen.width - w)/2;
	t = (screen.height - h)/2;
	return window.open(url,'_blank','top='+t+',left='+l+',width='+w+',height='+h + ',scrollbars=yes,resizable=yes,status=yes');
}
/**
*弹出窗口
*/
function openwin(url,name,w,h){
    l = (screen.width - w)/2;
	t = (screen.height - h)/2;
	return window.open(url,name,'top='+t+',left='+l+',width='+w+',height='+h + ',scrollbars=yes,resizable=yes,status=no');
}
/**
*弹出窗口
*/
function openwindow(url,w,h){
    l = (screen.width - w)/2;
	t = (screen.height - h)/2;
	return window.open(url,'_blank','top='+t+',left='+l+',width='+w+',height='+h + ',scrollbars=yes,resizable=yes,status=yes');
}
/**
*弹出窗口,可以指定弹出窗口的名字,可以调节窗口大小
*
*/
function OpenWindow(url,name,w,h){
    l = (screen.width - w)/2;
	t = (screen.height - h)/2;
	return window.open(url,name,'top='+t+',left='+l+',width='+w+',height='+h + ',scrollbars=yes,resizable=yes,status=no');
}
/**
*弹出窗口,可以指定弹出窗口的名字,不可以调节窗口大小
*
*/
function OpenWindow1(url,name,w,h){
    l = (screen.width - w)/2;
	t = (screen.height - h)/2;
	return window.open(url,name,'top='+t+',left='+l+',width='+w+',height='+h + ',scrollbars=no,resizable=yes,status=no');
}
/**
*弹出窗口
*/
function openWinLeft(url,name,w){
	return window.open(url,name,'top=0,left=0,width='+w+',height='+ (screen.height - 100) + ',scrollbars=no,resizable=no,status=no');
}
/**
*弹出窗口
*/
function openDialog(url,ob,w,h){
    return showModalDialog(url,ob,'dialogHeight:' + h + 'px;dialogWidth:' + w + 'px;scroll:no;resizable:no;status:no;');
}
/**
*弹出窗口
*/
function OpenDialog(url,ob,w,h,l,t){
    return showModalDialog(url,ob,'dialogHeight:' + h + 'px;dialogWidth:' + w + 'px;dialogLeft:' + l + ';dialogTop:' + t + ';scroll:no;resizable:no;status:no;');
}
/**
*弹出窗口,可以指定弹出窗口的名字,可以调节窗口大小
*
*/
function OpenWin(url,name,w,h){
    l = (screen.width - w)/2;
	t = (screen.height - h)/2;
	return window.open(url,name,'top='+t+',left='+l+',width='+w+',height='+h + ',scrollbars=no,resizable=yes,status=no');
}
/**
*检查必填项
*/
function CheckField(ObjForm){
	for(x = 0; x < ObjForm.length; x++){
		try{
			with(ObjForm[x]){
				if(style.checktype=='必填' && isBlank(value)){
					alert(style.prompt);
					try{
						select();
					}
                	catch(e){
            			focus();
        			}
					return false;
				}
				if(style.checktype=='数字' && (isBlank(value) || !isAllNum(value))){
					alert(style.prompt);
					try{
						select();
					}
					catch(e){
						focus();
					}
					return false;
				}
				if(style.checktype=='数值' && (isBlank(value) || !isNum(value))){
					alert(style.prompt);
					try{
						select();
						}
					catch(e){
						focus();
						}
					return false;
				}
				if(style.checktype=='字符' && (isBlank(value) || !isAllChar(value))){
					alert(style.prompt);
					try{
						select();
					}
                	catch(e){
            			focus();
        			}
					return false;
				}
				if(style.checktype=='整数' && (isBlank(value) || !IsInteger(value))){
					alert(style.prompt);
					try{
						select();
					}
                	catch(e){
            			focus();
        			}
					return false;
				}
				if(style.checktype=='货币' && (isBlank(value) || !isCurrency(value))){
					alert(style.prompt);
					try{
						select();
					}
                	catch(e){
            			focus();
        			}
					return false;
				}
				if(style.checktype=='邮件' && (isBlank(value) || !isValidMail(value))){
					alert(style.prompt);
					try{
						select();
					}
                	catch(e){
            			focus();
        			}
					return false;
				}
				if(style.checktype=='货币非必填' && !isBlank(value) && !isCurrency(value)){
					alert(style.prompt);
					try{
						select();
					}
                	catch(e){
            			focus();
        			}
					return false;
				}
			}
		}
		catch(e){
			continue;
		}
	}
	return true;
}
/**
*Email地址格式是否有效
*/
function isValidMail(Email) {

        checked_status = true;
		at_let = false;
		point_let = false;
        at_ps = -1;
		str_length = Email.length - 1;
        Email = Email.toUpperCase();

        for (i = 0; i <= str_length; i++) {
                ch = Email.charAt(i);
                if ((ch < 'A' || ch > 'Z') && (ch < '0' || ch > '9')) {
                        switch (ch) {
                                case '@' :
                                        {
                                                if (i == 0 || i == str_length || at_let) {
                                                        checked_status = false;
                                                }
                                                at_let = true;
                                                at_ps = i;
                                                break;
                                        }
                                case '.' :
                                        {
                                                if (i == 0 || i == str_length || i == at_ps + 1 || i == at_ps - 1) {
                                                        checked_status = false;
                                                }
                                                point_let = true;
                                                break;
                                        }
                                case '_' :
                                case '-' :
                                        {
                                                if (i == 0 || i == str_length) {
                                                        checked_status = false;
                                                }
                                                break;
                                        }
                                default :
                                        checked_status = false;
                                        break;
                        }
                }

                if (!checked_status) {
                        break;
                }
        }
		checked_status = checked_status & point_let & at_let;

        return checked_status;
	}

//组合多选checkbox
function combineCheckBox(checkboxes,ObjCombined){
	with(document.all){
		ObjCombined = eval(ObjCombined);
		ObjCombined.value = '';
		checkboxes = eval(checkboxes);
		isarray = false;
		try{
			if( 0 < checkboxes.length){
				isarray = true;
			}
		}
		catch(e){}
		if(isarray) {
			for(i = 0; i < checkboxes.length; i++ ){
				if(checkboxes[i].checked){
					ObjCombined.value += checkboxes[i].value + ',';
				}
			}
			return;
		}
		ObjCombined.value = checkboxes.value ;
		return;
	}
}

//判断是否为整形数字:sign 为 - or +,代表正负
function IsInteger(string){
	 return IsInteger(string ,'+');
}

function IsInteger(string ,sign){
	var integer;
	if ((sign!=null) && (sign!='-') && (sign!='+')){
		alert('IsInter(string,sign)的参数出错:\nsign为null或"-"或"+"');
		return false;
	}
	integer = parseInt(string);
	if (isNaN(integer))	{
		return false;
	}
	else if (integer.toString().length==string.length){
		if ((sign==null) || (sign=='-' && integer<0) || (sign=='+' && integer>0)){
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}

function clearQueryItems(){
	formname = 'PageForm';
	form = eval('document.all.' + formname);
	for(i = 0; i < form.length; i++){
		try{
			if(form[i].style.type == "query"){
				form[i].value = '';
			}
		}
		catch(e){
			continue;
		}
	}
}

/**
补位达到定长
src - 源字符串
charfill - 不够定用charfill补
len - 最终长度
**/
function padding(src,charfill,len){
	for (i = src.length; i < len; i++) {
		src = charfill + src;
    }
    return src;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -