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

📄 general.js

📁 j2ee源码
💻 JS
📖 第 1 页 / 共 5 页
字号:
//general.js
//requires var langID (baseLinkTag)
//         var resMgr.AppRootPath (baseLinkTag)

    var errorMsg = '';
    var errorNum = 0;
    var errorFocus;
    var dtCh =  '/';
    var minYear = 1900;
    var maxYear = 2100;
    var processing = false;
    var minMonth = 1;
    var maxMonth = 12;
    
    function startProcess()
    {
    	if (!processing){
		    processing = true;
		    return true;
		}
		else{
			processingAlert();
			return false;
		}
    }

    function processingAlert()
    {
        var lblprocessing = ""
		if (langId == 'cht'){
			lblprocessing = "請求正在處理中,不能接受新的請求。";
		}
		else if (langId == 'chs'){
			lblprocessing = "请求正在处理中,不能接受新的请求。";
		}
		else{
			lblprocessing = "Unable to process your request because another request is processing.";
		}
		alert(lblprocessing);
    }

    function initMsg()
    {
        errorMsg = '';
        errorNum = 0;
        errorFocus = null;
    }

    function isMsg(){
        return (errorNum > 0);
    }

    //Require initMsg();
    function showMsg()
    {
		if (langId == 'cht')
		{
			alert('輸入錯誤,請求不能夠被處理:\n\n' + errorMsg);
		}
		else if (langId == 'chs')
		{
			alert('输入错误,请求不能够被处理:\n\n' + errorMsg);
		}
		else
		{
			alert('Unable to process your request due to following error(s):\n\n' + errorMsg);
		}
        if (errorFocus != null)
        {
            errorFocus.focus();
        }
        initMsg();
    }

    //Require addMsg()
    function chkDdlEmpty(field, fieldName)
    {
		if ((trim(field.options[field.selectedIndex].value) == '') || (field.options[field.selectedIndex].value.length == 0))
        {
			if (langId == 'cht')
			{
				addMsg('請選擇' + fieldName + '。', field);
			}
			else if (langId == 'chs')
			{
				addMsg('请选择' + fieldName + '。', field);
			}
			else{
				addMsg('Please select the ' + fieldName + '.', field);
			}
            return false;
        }
        else
            return true;
    }

    //Require addMsg()
    function chkListEmpty(field, fieldName)
    {
        if (field.options.length == 0)
        {
            if (langId == 'cht')
			{
				addMsg('請選擇' + fieldName + '。', field);
			}
			else if (langId == 'chs')
			{
				addMsg('请选择' + fieldName + '。', field);
			}
			else{
				addMsg('Please select the ' + fieldName + '.', field);
			}
            return false;
        }
        else
            return true;
    }

    //Require addMsg()
    function chkListDuplicate(field, fieldName)
    {
        var dup = false;

        if (field.options.length > 1)
        {
            for (var i = 0; i < field.options.length; i++)
            {
                for (var j = i + 1; j < field.options.length; j++)
                {
                    if (field.options(i).value.substring(5) == field.options(j).value.substring(5))
                    {
                        dup = true;
                        break;
                    }
                }

                if (dup) break;
            }
        }

        if (dup){
			if (langId == 'cht')
			{
				addMsg('不可有重複的' + fieldName + '。');
			}
			else if (langId == 'chs')
			{
				addMsg('不可有重复的' + fieldName + '。');
			}
			else{
				addMsg('Duplicate ' + fieldName + ' is not allowed.');
			}
        }

        return dup;
    }
    
    //Check Year
    function chkTxtYear(field, fieldName, required)
    {
		if (trim(field.value) == '')
        {
			if (required == true)
			{
				if (langId == 'cht')
				{
					addMsg('請輸入' + fieldName + '。', field);
				}
				else if (langId == 'chs')
				{
					addMsg('请输入' + fieldName + '。', field);
				}
				else{
					addMsg('Please enter the ' + fieldName + '.', field);
				}
				return false;
			}
			else
			{
				return true;
			}
        }
		else if (isTxtYear(field.value))
		{
			return true;
		}
		else
		{
			if (langId == 'cht')
			{
				addMsg(fieldName + '必須是 ' + minYear + ' - ' + maxYear + ' 之間。', field);
			}
			else if (langId == 'chs')
			{
				addMsg(fieldName + '必须是 ' + minYear + ' - ' + maxYear + ' 之间。', field);
			}
			else{
				addMsg(fieldName + ' should be within ' + minYear + ' - ' + maxYear + '.', field);
			}
			return false;
		}
    }
    
    function isTxtYear(strYear)
    {
		if (IsNumeric(strYear, 4, 0))
		{
			var intYear = parseInt(strYear);
			if (intYear >= minYear && intYear <= maxYear)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
    }
    
    function isEmpty(field)
    {
        if (trim(field.value) == '')
        {
            return true;
        }
        else
            return false;
    }

    //Require addMsg()
    function chkEmpty(field, fieldName)
    {
        if (trim(field.value) == '')
        {
			if (langId == 'cht')
			{
				addMsg('請輸入' + fieldName + '。', field);
			}
			else if (langId == 'chs')
			{
				addMsg('请输入' + fieldName + '。', field);
			}
			else{
				addMsg('Please enter the ' + fieldName + '.', field);
			}
            return false;
        }
        else
            return true;
    }

    //Require IsNumeric()
    //Require addMsg()
    function chkTxtNum(field, fielddesc, totdigit, dp, required)
    {
        var numPart;
        var digit = totdigit - dp;

        if (field.value != ""){

            /*
            if (field.value.substring(0,1) == "-")
            {
                numPart = field.value.substring(1,field.value.length);
            }
            else
            {
                numPart = field.value;
            }

            if (!IsNumeric(numPart, digit, dp))
            */

            if (!isTxtNum(field.value, totdigit, dp))
            {
                if (dp > 0)
                {
					if (langId == 'cht')
					{
						addMsg(fielddesc + "必須是"+ digit + "個數字及" + dp + "個小數位。", field);			
					}
					else if (langId == 'chs')
					{
						addMsg(fielddesc + "必须是"+ digit + "个数字及" + dp + "个小数位。", field);			
					}
					else{
						addMsg(fielddesc + " should be numeric in "+ digit + " digits and " + dp + " decimal place.", field);			
					}
                }
                else
                {
					if (langId == 'cht')
					{
						addMsg(fielddesc + "必須是"+ digit + "個數字。", field);			
					}
					else if (langId == 'chs')
					{
						addMsg(fielddesc + "必须是"+ digit + "个数字。", field);			
					}
					else{
						addMsg(fielddesc + " should be numeric in "+ digit + " digits.", field);
					}	
                }

                return false;
            }
            else
            {
                return true;
            }
        }
        else
        {
            if (required)
            {
                return chkEmpty(field, fielddesc);
            }
            else
            {
				return true;
            }
        }
    }
    
    function isTxtNum(fieldvalue, totdigit, dp)
    {
        var numPart;
        var digit = totdigit - dp;

        if (fieldvalue != ""){

            if (fieldvalue.substring(0,1) == "-")
            {
                numPart = fieldvalue.substring(1,fieldvalue.length);
            }
            else
            {
                numPart = fieldvalue;
            }

            if (!IsNumeric(numPart, digit, dp))
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }
    

    /*function chkTxtNumValue(fieldvalue, fielddesc, totdigit, dp)
    {
        var numPart;
        var digit = totdigit - dp;

        if (fieldvalue != ""){

            if (fieldvalue.substring(0,1) == "-")
            {
                numPart = fieldvalue.substring(1,fieldvalue.length);
            }
            else
            {
                numPart = fieldvalue;
            }

            if (!IsNumeric(numPart, digit, dp))
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }*/

    function isInteger(value)
    {
        if (value.search(/^-{0,1}[0-9]+$/) == (-1))
            return false;
        else
            return true;
    }

    //Require IsIntPart();
    //Require IsDecPart();
    function IsNumeric(numStr, digit, dp)
    {
        var pos1;
        var pos2;
        var strInt;
        var strDec;

        if (numStr == "")
        {
            return false;
        }
        else
        {
            pos1=numStr.indexOf(".");
            pos2=numStr.indexOf(".",pos1+1);
            if (pos1 == -1){
                strInt = numStr;
                strDec = "";
            }
            else{
                strInt=numStr.substring(0,pos1);
                if (pos1 != -1){
                    strDec=numStr.substring(pos1+1);
                }
                else{
                    strDec = "";
                }
            }

            if (pos2 != -1)
            {
                return false;
            }
            else
            {
                if (!IsIntPart(strInt, digit)) return false;
                if (!IsDecPart(strDec, dp)) return false;
                return true;
            }
        }
    }

    //  check for valid numeric strings
    function IsIntPart(strString, digit)
    {
        var strValidChars = "0123456789,";
        var strChar;
        var blnResult = true;
        var cnt = 0;
        var loopcnt = 0;

⌨️ 快捷键说明

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