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

📄 general.js

📁 j2ee源码
💻 JS
📖 第 1 页 / 共 5 页
字号:
        return true;
    }

    function toCrystalString(strValue){
        return '\\\"' +  strValue + '\\\"';
    }
    
    function Round(data,dp)
	{
		var f = Math.pow(10, dp + 1);
		if (parseInt(data * f) % 5 == 0){
			if (data >= 0){
				data = data + (1 / f);
			}
			else{
				data = data - (1 / f);
			}
				
		}
		var x = Math.round(data * Math.pow(10, dp));
		var y = Math.pow(10, dp);

		return x/y;
	}
    
    function formatNumeric(fltValue,intDecimal){
	    fltValue = '' + fltValue;
		var value = parseTxtNum(fltValue);
		var pnumber = Round(value, intDecimal);
		var snum = new String(pnumber);
		if (snum.indexOf('.') < 0)
		{
			var sec = snum.split('.');  
			var whole = new String(sec[0]); 
			var dec = ''; 		
		}
		else
		{
			var sec = snum.split('.');  
			var whole = new String(sec[0]); 
			var dec = new String(sec[1]); 
		}
		
		var todec = parseInt(intDecimal); 
		while(dec.length < todec)
		{
     		dec += '0';
		}
		sign = whole.substring(0,1);
		if (sign == '-'){
			whole = whole.substring(1,whole.length);
		}
		else
		{
			sign = '';
		}
		if (dec != '')
		{
			return sign + formatIntPart(whole) + "." + dec;
		}
		else
		{
			return sign + formatIntPart(whole);
		}
	}
	
    //Require isDateCompNotEqual()
    //Require addMsg()
    function chkDateCompNotEqual(field1, fieldName1, field2, fieldName2)
    {
        if (isDateCompNotEqual(field1.value, field2.value) == false)
        {
            addMsg(fieldName2 + ' <= ' + fieldName1, field1);
            return false;
        }
        else
        {
            return true;
        }
    }

    function isDateCompNotEqual(value1, value2)
    {
        var daysInMonth = DaysArray(12)

        var value1_pos1 = value1.indexOf(dtCh);
        var value1_pos2 = value1.indexOf(dtCh,value1_pos1+1);
        var value2_pos1 = value2.indexOf(dtCh);
        var value2_pos2 = value2.indexOf(dtCh,value2_pos1+1);

        var value1_strDay = value1.substring(0,value1_pos1);
        var value1_strMonth = value1.substring(value1_pos1+1,value1_pos2);
        var value1_strYear = value1.substring(value1_pos2+1);
        var value2_strDay = value2.substring(0,value2_pos1);
        var value2_strMonth = value2.substring(value2_pos1+1,value2_pos2);
        var value2_strYear = value2.substring(value2_pos2+1);

        if ((value1_strDay.charAt(0) == '0') && (value1_strDay.length > 1))
            value1_strDay = value1_strDay.substring(1);
        if ((value1_strMonth.charAt(0) == '0') && (value1_strMonth.length > 1))
            value1_strMonth = value1_strMonth.substring(1);
        for (var i = 1; i <= 3; i++)
        {
            if ((value1_strYear.charAt(0) == '0') && (value1_strYear.length > 1))
                value1_strYear = value1_strYear.substring(1);
        }
        if ((value2_strDay.charAt(0) == '0') && (value2_strDay.length > 1))
            value2_strDay = value2_strDay.substring(1);
        if ((value2_strMonth.charAt(0) == '0') && (value2_strMonth.length > 1))
            value2_strMonth = value2_strMonth.substring(1);
        for (var i = 1; i <= 3; i++)
        {
            if ((value2_strYear.charAt(0) == '0') && (value2_strYear.length > 1))
                value2_strYear = value2_strYear.substring(1);
        }

        var value1_day = parseInt(value1_strDay);
        var value1_month = parseInt(value1_strMonth);
        var value1_year = parseInt(value1_strYear);
        var value2_day = parseInt(value2_strDay);
        var value2_month = parseInt(value2_strMonth);
        var value2_year = parseInt(value2_strYear);

        if (value2_year > value1_year)
            return true;
        else if ((value2_month > value1_month) && (value2_year == value1_year))
            return true;
        else if ((value2_day > value1_day) && (value2_month == value1_month) && (value2_year == value1_year))
            return true;
        else
            return false;
    }

    function toCrystalDateTime(strDate){
        var pos1 = strDate.indexOf('/');
        var pos2 = pos1 + strDate.substring(pos1+1,strDate.length).indexOf('/') + 1;
        var pos3 = strDate.length;

        return 'Date(' + strDate.substring(pos2+1,pos3) + ',' + strDate.substring(pos1+1,pos2) + ',' + strDate.substring(0,pos1) + ')';
    }

    function chkMonthEqual(field1, fieldName1, field2, fieldName2)
    {
        if (isMonthEqual(field1.value, field2.value) == false)
        {
				if (langId == 'cht')
				{
					addMsg(fieldName1 + '和' + fieldName2 + '的年份及月份必須相同。',field1);
				}
				else if (langId == 'chs')
				{
					addMsg(fieldName1 + '和' + fieldName2 + '的年份及月份必须相同。',field1);
				}
				else{
					addMsg('Month and Year of ' + fieldName1 + ' and ' + fieldName2 + ' must be equal.',field1);
				}
            return false;
        }
        else
        {
            return true;
        }
    }

    function isMonthEqual(value1, value2)
    {
        var daysInMonth = DaysArray(12)

        var value1_pos1 = value1.indexOf(dtCh);
        var value1_pos2 = value1.indexOf(dtCh,value1_pos1+1);
        var value2_pos1 = value2.indexOf(dtCh);
        var value2_pos2 = value2.indexOf(dtCh,value2_pos1+1);

        var value1_strDay = value1.substring(0,value1_pos1);
        var value1_strMonth = value1.substring(value1_pos1+1,value1_pos2);
        var value1_strYear = value1.substring(value1_pos2+1);
        var value2_strDay = value2.substring(0,value2_pos1);
        var value2_strMonth = value2.substring(value2_pos1+1,value2_pos2);
        var value2_strYear = value2.substring(value2_pos2+1);

        if ((value1_strDay.charAt(0) == '0') && (value1_strDay.length > 1))
            value1_strDay = value1_strDay.substring(1);
        if ((value1_strMonth.charAt(0) == '0') && (value1_strMonth.length > 1))
            value1_strMonth = value1_strMonth.substring(1);
        for (var i = 1; i <= 3; i++)
        {
            if ((value1_strYear.charAt(0) == '0') && (value1_strYear.length > 1))
                value1_strYear = value1_strYear.substring(1);
        }
        if ((value2_strDay.charAt(0) == '0') && (value2_strDay.length > 1))
            value2_strDay = value2_strDay.substring(1);
        if ((value2_strMonth.charAt(0) == '0') && (value2_strMonth.length > 1))
            value2_strMonth = value2_strMonth.substring(1);
        for (var i = 1; i <= 3; i++)
        {
            if ((value2_strYear.charAt(0) == '0') && (value2_strYear.length > 1))
                value2_strYear = value2_strYear.substring(1);
        }

        var value1_day = parseInt(value1_strDay);
        var value1_month = parseInt(value1_strMonth);
        var value1_year = parseInt(value1_strYear);
        var value2_day = parseInt(value2_strDay);
        var value2_month = parseInt(value2_strMonth);
        var value2_year = parseInt(value2_strYear);

        if ((value2_year == value1_year) && (value2_month == value1_month) )
            return true;
        else
            return false;
    }
    
    function parseTxtNum(value)
    {
    	var numStr = replaceSubstring(value,',','')
    	return parseFloat(numStr);
    }

    function chkStrCompEqualIgnoreCase(field1, fieldName1, field2, fieldName2)
    {
        if (isStrCompEqual(field1.value.toUpperCase(), field2.value.toUpperCase()) == false)
        {
            addMsg(fieldName2 + ' < ' + fieldName1, field1);
            return false;
        }
        else
            return true;
    }

    //function formatIntField(field){
    //  var signPart = "";
    //var numPart = "";
    //  if (field.value.substring(0,1) == "-" || field.value.substring(0,1) == "+" ){
    //      numPart = field.value.substring(1,field.value.length);
    //      signPart = "-"
    //  }
    //  else{
    //      numPart = field.value;
    //      signPart = ""
    //  }
    //  numStr = replaceSubstring(numPart,',','')
    //  field.value = signPart + formatIntPart(numStr);
    //}
     
    function formatNumField(field){
    	var key = window.event.keyCode;
    	//not a <-, -> or TAB
    	if (key != 37 && key !=39 && key != 9){
		    var signPart = "";
		    var numPart = "";
		    if (field.value.substring(0,1) == "-" || field.value.substring(0,1) == "+" ){
		        numPart = field.value.substring(1,field.value.length);
		        signPart = "-"
		    }
		    else{
		        numPart = field.value;
		        signPart = ""
		    }
		    numStr = replaceSubstring(numPart,',','')
		
		    var pos1=numStr.indexOf(".");
		    var 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(pos1 > 0){
		        field.value = signPart + formatIntPart(strInt) + "." + strDec;
		    }
		    else{
		        field.value = signPart + formatIntPart(strInt);
		    }
		}
    }

    function formatIntPart(number) {
        if (isInteger(number)){
            number = '' + number;
            if (number.length > 3) {
                var mod = number.length % 3;
                var output = (mod > 0 ? (number.substring(0,mod)) : '');
                for (i=0 ; i < Math.floor(number.length / 3); i++) {
                    if ((mod == 0) && (i == 0))
                        output += number.substring(mod + 3 * i, mod + 3 * i + 3);
                    else
                        output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
                }
                return output
            }
            else return number;
        }
        else{
            return number;
        }
    }

    function ToDate(dateString)
    {
        var dates = dateString.split("-");
        var dd = parseFloat(dates[0]);
        var mm = parseFloat(dates[1]) - 1;
        var yyyy = parseFloat(dates[2]);
        var date = new Date(2004, 1, 1);
        date.setFullYear(yyyy);
        date.setMonth(mm);
        date.setDate(dd);
        return date;
    }

    function isValidKeyValue(fValue) {
        var strChar;
        var strValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._";

        if (fValue == null)
        {
            return true;
        }else if (fValue == '')
        {
            return true;
        }
        else
        {
            for (i = 0; i < fValue.length; i++)
            {
                strChar = fValue.charAt(i);
                if (strValidChars.indexOf(strChar) == -1 )
                {
                    return false;
                }
            }
            return true;
        }
    }

    function chkKey(field, fieldName){

        var strString = field.value;
        var strValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._#-/()& ";
        var blnResult = true;

        if (field == null)
        {
            return true;
        }else if (strString == '')
        {
            return true;
        }
        else
        {
            for (i = 0; i < strString.length && blnResult == true; i++)
            {
                strChar = strString.charAt(i);
                if (strValidChars.indexOf(strChar) == -1 )
                {
                    blnResult = false;
                }
            }

            if (!blnResult)
            {
				if (langId == 'cht')
				{
					addMsg(fieldName + '不可含有非英文字及特別符號。', field);
				}
				else if (langId == 'chs')
				{
					addMsg(fieldName + '不可含有非英文字及特别符号。', field);
				}
				else
				{
					addMsg(fieldName + ' should not contains Non-English and special characters.', field);
				}
                return false;
            }
            else
            {
                return true;
            }
        }
    }
   
	// CONSTANTS
	var separator = ",";  // use comma as 000's separator
	var decpoint = ".";  // use period as decimal point
	var percent = "%";
	var currency = "$";  // use dollar sign for currency

	function formatNumber(number, format, print) {  // use: formatNumber(number, "format")
	if (print) document.write("formatNumber(" + number + ", \"" + format + "\")<br>");

	if (number - 0 != number) return null;  // if number is NaN return null
	var useSeparator = format.indexOf(separator) != -1;  // use separators in number
	var usePercent = format.indexOf(percent) != -1;  // convert output to percentage
	var useCurrency = format.indexOf(currency) != -1;  // use currency format
	var isNegative = (number < 0);
	number = Math.abs (number);
	if (usePercent) number *= 100;
	format = strip(format, separator + percent + currency);  // remove key characters
	number = "" + number;  // convert number input to string

		// split input value into LHS and RHS using decpoint as divider
	var dec = number.indexOf(decpoint) != -1;
	var nleftEnd = (dec) ? number.substring(0, number.indexOf(".")) : number;
	var nrightEnd = (dec) ? number.substring(number.indexOf(".") + 1) : "";

		// split format string into LHS and RHS using decpoint as divider
	dec = format.indexOf(decpoint) != -1;
	var sleftEnd = (dec) ? format.substring(0, format.indexOf(".")) : format;
	var srightEnd = (dec) ? format.substring(format.indexOf(".") + 1) : "";

		// adjust decimal places by cropping or adding zeros to LHS of number
	if (srightEnd.length < nrightEnd.length) {
		var nextChar = nrightEnd.charAt(srightEnd.length) - 0;
		nrightEnd = nrightEnd.substring(0, srightEnd.length);
		if (nextChar >= 5) nrightEnd = "" + ((nrightEnd - 0) + 1);  // round up

		while (srightEnd.length > nrightEnd.length) {
		nrightEnd = "0" + nrightEnd;
		}

		if (srightEnd.length < nrightEnd.length) {
		nrightEnd = nrightEnd.substring(1);
		nleftEnd = (nleftEnd - 0) + 1;
		}
	} else {
		for (var i=nrightEnd.length; srightEnd.length > nrightEnd.length; i++) {
		if (srightEnd.charAt(i) == "0") nrightEnd += "0";  // append zero to RHS of number
		else break;
		}
	}

		// adjust leading zeros
	sleftEnd = strip(sleftEnd, "#");  // remove hashes from LHS of format
	while (sleftEnd.length > nleftEnd.length) {

⌨️ 快捷键说明

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