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

📄 tools.js

📁 CRM项目的相关文件
💻 JS
📖 第 1 页 / 共 2 页
字号:
<!--
//to replace all string1 with string2 in a fixed string.
function replaceString(s,s1,s2){
  if(s.indexOf(s1)>=0){
    s=s.substring(0,s.indexOf(s1))+s2+s.substring(s.indexOf(s1)+s1.length);
    s=replaceString(s,s1,s2);
  }
  return s;
}

//将HTML编码转换为实际对应的字符,得到真正的字符串
function getRealString(s){
  s=replaceString(s,"&lt;","<");
  s=replaceString(s,"&gt;",">");
  s=replaceString(s,"&amp;","&");
  s=replaceString(s,"&quot;","\"");

  return s;
}

//to open a new window without status
function openwin(URL,winName,leftMargin,topMargin,winWidth,winHeight){
  window.open(URL,winName,"left=" + leftMargin + " top=" + topMargin + " width=" + winWidth + ", height=" + winHeight + " menu=yes status=yes resizable=no scrollbars=yes");
}

//判断是否是正整数
function isInteger(inputVal){
  inputStr=inputVal.toString();

  for(var i=0;i<inputStr.length;i++) {
    var oneChar=inputStr.charAt(i);
//    if(i==0&&oneChar=="0")
//      return false;
    if(oneChar<"0"||oneChar>"9"){
      return false;
    }
  }
  return true;
}

//判断是否是正整数,加提示
function isInteger(inputVal, strName){
  inputStr=inputVal.toString();

  for(var i=0;i<inputStr.length;i++) {
    var oneChar=inputStr.charAt(i);
//    if(i==0&&oneChar=="0")
//      return false;
    if(oneChar<"0"||oneChar>"9"){
      alert("栏目‘"+strName+"’只能填写不小于0的整数");
      return false;
    }
  }
  return true;
}

//判断是否是空字符串或空格字符串
function isVoidStr(inputVal){
  if(inputVal.length==0){
    return true;
  } else {
    var oneChar="";
    for(var i=0;i<inputVal.length;i++) {
      oneChar=inputVal.charAt(i);
      if(oneChar!=' ') {
        return false;
      }
    }
  }
  return true;
}

//判断EAMIL是否合法
function check_email(address) {
  var address=address;
  if ((address == "") || (address.indexOf ('@') == -1) || (address.indexOf ('.') == -1))
    return false;
  return true;
}

//得到字符串的字节长度
function calculateStrLen(str){
  var i,intLen=0;
  for(i=0;i<str.length;i++){
    if (str.charCodeAt(i)>126){
      intLen++;
    }
    intLen++;
  }
  return intLen;
}

function emailVerify(objText,blnEmpty,intLength,strName ){
  //校验邮件录入的有效性,有效返回true,无效返回false
  var strText=objText.value;

  if(strText=="" && blnEmpty==false){
    alert("‘" + strName + "’不能为空!");
    objText.focus();
    return false;
  }

  if( strText.length > intLength){
    alert("‘" + strName + "’不能超过 " + intLength + " 个字符,请更正!");
    objText.select();
    return false;
  }

  if ((strText == "") || (strText.indexOf ('@') == -1) || (strText.indexOf ('.') == -1)){
     alert("‘" + strName + "’的格式不正确!");
     objText.select();
     return false;
  }

  return true;
}

function teleVerify(objText,blnEmpty,intLength,strName ){
//校验电话号码录入的有效性,有效返回true,无效返回false
  var strText=objText.value;

  if(strText=="" && blnEmpty==false){
    alert("‘" + strName + "’不能为空!");
    objText.focus();
    return false;
  }

  if( strText.length > intLength){
    alert("‘" + strName + "’不能超过 " + intLength + " 个字符,请更正!");
    objText.select();
    return false;
  }

  var i;
  for(i=0;i<strText.length;i++){
    if((strText.charCodeAt(i)<48 || strText.charCodeAt(i)>57) &&  strText.charCodeAt(i)!=45){
      alert("‘" + strName + "’只能填写数字和连字符‘-’");
      objText.select();
      return false;
    }
  }
  return true;
}

function telVerify(objText,intLength,strName ){
//校验电话号码录入的有效性,有效返回true,无效返回false
  var strText=Trim(objText.value);

  if( strText.length > intLength){
    alert("栏目‘"+strName+"’不能超过 "+intLength+" 个字符,请更正。");
    objText.select();
    return false;
  }

  var i;
  for(i=0;i<strText.length;i++){
    if((strText.charCodeAt(i)<48 || strText.charCodeAt(i)>57) &&  strText.charCodeAt(i)!=45){
      alert("栏目‘"+strName+"’只能填写数字和连字符‘-’");
      objText.select();
      return false;
    }
  }
  return true;
}

function textVerify(objText,blnEmpty,intLength,strName) {
	//校验文本录入的有效性,有效返回true,无效返回false
	//objText为待校验的页面表单对象;blnEmpty表示此文本是否可为空,true表示可为空,false表示不可为空;
	//intLength最大字节长度;strName校验的对象栏目的名称

	var strText=objText.value;
	var newText=trim(strText);
	objText.value=newText;

	if(newText=="" && blnEmpty==false) {
		alert("‘" + strName + "’不能为空!");
		if(objText.type!="hidden") {
			objText.focus();
		}
		return false;
	}

	if(calculateStrLen(strText) > intLength) {
		alert("‘" + strName + "’超过了指定的长度(" + intLength + "字符),请更正!");
		if(objText.type!="hidden") {
			objText.focus();
		}
		return false;
	}

    return true;
}

function charVerify(objText,blnEmpty,intLength,strName ){
//校验纯字母文本录入的有效性,有效返回true,无效返回false
  var strText=Trim(objText.value);
  if(strText=="" && blnEmpty==false){
    alert("栏目‘"+strName+"’不能为空。");
    objText.focus();
    return false;
  }
  var i;
  for(i=0;i<strText.length;i++){
    if(strText.charCodeAt(i)!=32){
      if(strText.charCodeAt(i)<65 || ( strText.charCodeAt(i)>90 && strText.charCodeAt(i)<97 )  ||  strText.charCodeAt(i)>122 ){
        alert("栏目‘"+strName+"’只能填写字母。");
        objText.select();
        return false;
      }
    }
  }
  if(strText.length > intLength){
    alert("栏目‘"+strName+"’不能超过 "+intLength+" 个字符,请更正。");
    objText.select();
    return false;
  }
  return true;
}

function char_numVerify(objText,blnEmpty,intLength,strName ){
//校验纯字母和数字文本录入的有效性,有效返回true,无效返回false
  var strText=Trim(objText.value);
  if(strText=="" && blnEmpty==false){
    alert("栏目‘"+strName+"’不能为空。");
    objText.focus();
    return false;
  }
  var i;
  for(i=0;i<strText.length;i++){
    if(strText.charCodeAt(i)!=32){
      if(strText.charCodeAt(i)<48 || ( strText.charCodeAt(i)>57 && strText.charCodeAt(i)<65 )  || ( strText.charCodeAt(i)>90 && strText.charCodeAt(i)<97 )  ||  strText.charCodeAt(i)>122 ){
        alert("栏目‘"+strName+"’只能填写字母和数字。");
        objText.select();
        return false;
      }
    }
  }
  if(strText.length > intLength){
    alert("栏目‘"+strName+"’不能超过 "+intLength+" 个字符,请更正。");
    objText.select();
    return false;
  }
  return true;
}

function numberVerify(objText,blnEmpty,intLength,strName ){
//校验纯数字文本录入的有效性,有效返回true,无效返回false
  var strText=Trim(objText.value);
  if(strText=="" && blnEmpty==false){
    alert("栏目‘"+strName+"’不能为空。");
    objText.focus();
    return false;
  }
  var i;
  for(i=0;i<strText.length;i++){
    if((strText.charCodeAt(i)<48 || strText.charCodeAt(i)>57)){
      alert("栏目‘"+strName+"’只能填写数字。");
      objText.select();
      return false;
    }
  }
  if(strText.length > intLength){
    alert("栏目‘"+strName+"’不能超过 "+intLength+" 个字符,请更正。");
    objText.select();
    return false;
  }
  return true;
}

function positiveIntVerify(objText,blnEmpty,intLength,strName){
//校验正整数录入的有效性,有效返回true,无效返回false
 var strText=objText.value;
  if(strText=="" && blnEmpty==false){
    alert("栏目‘"+strName+"’不能为空。");
    objText.focus();
    return false;
  }
  var i;
  for(i=0;i<strText.length;i++){
	  
    if((strText.charCodeAt(0)==48 || strText.charCodeAt(i)<48 || strText.charCodeAt(i)>57)){
      alert("栏目‘"+strName+"’只能填写正整数。");
      objText.select();
      return false;
	
    }
  }
  if(strText.length > intLength){
    alert("栏目‘"+strName+"’不能超过 "+intLength+" 个字符,请更正。");
    objText.select();
    return false;
  }
  return true;


}

function intVerify(objText,blnEmpty,intLength,strName ){
//校验整数文本录入的有效性,有效返回true,无效返回false
  var strText=Trim(objText.value);
  if(strText=="" && blnEmpty==false){
    alert("栏目‘"+strName+"’不能为空。");
    objText.focus();
    return false;
  }
  var i;
  for(i=0;i<strText.length;i++){
    if((strText.charCodeAt(i)<48 || strText.charCodeAt(i)>57)){
      alert("栏目‘"+strName+"’只能填写整数。");
      objText.select();
      return false;
    }
  }
  if(strText.length > intLength){
    alert("栏目‘"+strName+"’不能超过 "+intLength+" 个字符,请更正。");
    objText.select();
    return false;
  }
  return true;
}
/*
	trim the blank space both head and tail.
	@param str input string
	@return string without blank space head and tail
*/
function trim(str){
	var regExp = /[^\s]+(\s+[^\s]+)*/;
	if(str == null)
		return str;

	var matchs = str.match(regExp);
	if(matchs != null)
		return matchs[0];

	return "";
}

function dateOrderVerify(objStart,objEnd,blnEmpty,strStartName,strEndName ){
//校验关联日期的有效性,有效返回true,无效返回false
  var strStart=objStart.value;
  var strEnd=objEnd.value;
  if(blnEmpty){
    if(strStart=="" || strEnd==""){
      return true;
    }
  }else{
    if(strStart==""){
      alert(strStartName + "不能为空!");
      objStart.focus();
      return false;
    }
    if(strEnd==""){
      alert("‘" + strEndName + "’不能为空!");
      objEnd.focus();
      return false;
    }
  }

  var intStart=(strStart.substring(0,4))*10000 + (strStart.substring(5,7))*100 + (strStart.substring(8,10));
  var intEnd=(strEnd.substring(0,4))*10000 + (strEnd.substring(5,7))*100 + (strEnd.substring(8,10));
  if(intStart>intEnd){
    alert("‘" + strStartName + "’指定的日期不能比‘" + strEndName + "’指定的日期晚!");
    objStart.focus();
    return false;

⌨️ 快捷键说明

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