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

📄 jsfunc.js

📁 实习的时候做的数字校园系统
💻 JS
📖 第 1 页 / 共 2 页
字号:
function TrimString (strVal)
{
    strTmp = strVal + "";
    if (strTmp.length == 0)
        return (strTmp);
    reVal = /^(\s| )*/;
    strTmp = strTmp.replace (reVal, '');
    reVal = /(\s| )*$/;
    return (strTmp.replace (reVal, ''));
}
function HtmlFormat (strVal)
{
    reVal = /</g;
    strTmp = strVal.replace (reVal, "&lt;");
    reVal = />/g;
    strTmp = strTmp.replace (reVal, "&gt;");
    reVal = /"/g;
    strTmp = strTmp.replace (reVal, "&quot;");
    return (strTmp);
}
function UrlStringFormat (strVal)
{
    reVal = /%/g;
    strTmp = strVal.replace (reVal, "%25");
    reVal = /&/g;
    strTmp = strTmp.replace (reVal, "%26");
    reVal = /#/g;
    strTmp = strTmp.replace (reVal, "%23");
    reVal = /\+/g;
    strTmp = strTmp.replace (reVal, "%2b");
    return (strTmp);
}
function CheckNumber (strVal)
{
    strVal = TrimString (strVal);
    if (strVal.length == "")
        return (false);
    reVal = /^[\-\+]?([0-9]\d*|0|[1-9]\d{0,2}(,\d{3})*)(\.\d+)?$/;
    if (reVal.test (strVal))
    {
        gar = strVal + '.';
        tmp = gar.split ('.');
        if (tmp[0].length > 15)
            return (false);
        else
            return (true);
    }
    return (false);
}
function CheckInteger (strVal)
{
    strVal = TrimString (strVal);
    if (strVal.length == "")
        return (false);
    reVal = /^[\-\+]?([1-9]\d*|0|[1-9]\d{0,2}(,\d{3})*)$/;
    return (reVal.test (strVal));
}
function CheckEmail (strEmail)
{
    strEmail = (TrimString (strEmail));
    if (strEmail.length == 0)
        return (false);
    reVal = /^[\-!#\$%&'\*\+\\\.\/0-9=\?A-Z\^_`a-z{|}~]+@[\-!#\$%&'\*\+\\\.\/0-9=\?A-Z\^_`a-z{|}~]+(\.[\-!#\$%&'\*\+\\\.\/0-9=\?A-Z\^_`a-z{|}~]+)+$/;
    return (reVal.test (strEmail));
}
function CheckTime (strTime)
{
    strTime = (TrimString (strTime));
    if (strTime.length == 0)
        return (false);
    reVal = /^(([0-9]|[01][0-9]|2[0-3])(:([0-9]|[0-5][0-9])){0,2}|(0?[0-9]|1[0-1])(:([0-9]|[0-5][0-9])){0,2}\s?[aApP][mM])?$/;
    return (reVal.test (strTime));
}
function CheckDate (strDate)
{
    var nStart;
    var nEnd;
    var nYear;
    var nMonth;
    var nDay;
    var nFact;
    var arrDay = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    strDate = (TrimString (strDate));
    if (strDate.length == 0)
        return (false);
    reVal = /^([1-2]\d{3})[\/|\-](0?[1-9]|10|11|12)[\/|\-]([1-2]?[0-9]|0[1-9]|30|31)$/;
    if (!reVal.test (strDate))
        return (false);
    nStart = strDate.indexOf ("/", 0);
    nEnd = strDate.indexOf ("/", nStart + 1);
    nYear = eval (strDate.substring (0, nStart));
    nMonth = eval (strDate.substring (nStart + 1, nEnd));
    nDay = eval (strDate.substring (nEnd + 1, strDate.length));
    nFact = arrDay[nMonth - 1];
    if (nMonth == 2)
    {
        if ((nYear % 4 == 0 && nYear %100 != 0) || (nYear % 400 == 0))
            nFact ++;
    };
    if (nDay > nFact)
        return (false);
    return (true);
}
function CheckEditInteger (strVal)
{
    strVal = TrimString (strVal);
    if (strVal.length == "")
        return (false);
    reVal = /^[\-\+]?([0-9]\d*|0|[1-9]\d{0,2}(,\d{3})*)$/;
    return (reVal.test (strVal));
}

function IntTo2Char (nVal)
{
    if (nVal <= 9)
        strOut = "0";
    else
        strOut = "";
    strOut += nVal;
    return (strOut);
}
function AdjustTime (strVal)
{
    strVal = TrimString (strVal);
    if (strVal == "")
        return ("");
    nPos = strVal.indexOf (":", 0);
    if (nPos < 0)
    {
        if (CheckEditInteger (strVal))
            nHour = Math.ceil (strVal);
        else
            nHour = 0;
        nMinute = 0;
        nSecond = 0;
    }
    else
    {
        if (nPos == 0)
            nHour = 0;
        else
        {
            strTmp = strVal.substring (0, nPos);
            if (CheckEditInteger (strTmp))
                nHour = Math.ceil (strTmp);
            else
                nHour = 0;
        };
        strVal = strVal.substring (nPos + 1, strVal.length + 1);
        nPos = strVal.indexOf (":");
        if (nPos < 0)
        {
            if (CheckEditInteger (strVal))
                nMinute = Math.ceil (strVal);
            else
                nMinute = 0;
            nSecond = 0;
        }
        else
        {
            if (nPos == 0)
                nMinute = 0;
            else
            {
                strTmp = strVal.substring (0, nPos);
                if (CheckEditInteger (strTmp))
                    nMinute = Math.ceil (strTmp);
                else
                    nMinute = 0;
            };
            strTmp = strVal.substring (nPos + 1, strVal.length + 1);
            if (CheckEditInteger (strTmp))
                nSecond = Math.ceil (strTmp);
            else
                nSecond = 0;
        };
    };
    if (nHour < 0)
        nHour = 0;
    else if (nHour > 23)
        nHour = 23;
    if (nMinute < 0)
        nMinute = 0;
    else if (nMinute > 59)
        nMinute = 59;
    if (nSecond < 0)
        nSecond = 0;
    else if (nSecond > 59)
        nSecond = 59;
    return (IntTo2Char (nHour) + ":" + IntTo2Char (nMinute) + ":" + IntTo2Char (nSecond));
}

function ByteString (strVal)
{
    nLen = 0;
    for (i = 0; i < strVal.length; i ++)
    {
        if (strVal.charCodeAt (i) > 255)
            nLen += 2;
        else
            nLen ++;
    };
    return (nLen);
}
function ByteSubString (strVal, nLength)
{
    if (nLength == 0)
        return ("");
    strOut = "";
    nLen = 0;
    for (i = 0; i < strVal.length; i ++)
    {
        if (strVal.charCodeAt (i) <= 255)
        {
            nLen ++;
            strOut = strOut + strVal.charAt (i);
            if (nLen == nLength)
                break;
        }
        else
        {
            nLen += 2;
            if (nLen > nLength)
                break;
            strOut = strOut + strVal.charAt (i);
            if (nLen == nLength)
                break;
        };
    }
    return (strOut);
}
function FillString (strVal, strChar, nLength, bLeft)
{
    nLen = strVal.length;
    if (nLen >= nLength)
        return (strVal);
    if (strChar == "")
        chVal = " ";
    else
        chVal = strChar.substring(0, 1);
    strFill = "";
    for (i = 0; i < nLength - nLen; i ++)
        strFill = strFill + chVal;
    if (bLeft)
        return (strFill + strVal);
    else
        return (strVal + strFill);
}

function CheckValidCode (strCode)
{
    if (strCode.length == 0)
        return (false);
    for (i = 0; i < strCode.length; i ++)
    {
        strChar = strCode.substring (i, i + 1).toUpperCase ();
        if (!((strChar >= "A" && strChar <= "Z") || (strChar >= "0" && strChar <= "9")))
            return (false);
    };
    return (true);
}

function CheckIPAddr (strVal)
{
    strVal = (TrimString (strVal));
    if (strVal.length == 0)
        return (false);
    reVal = /^(\d{1}|\d{2}|[0-1]\d{2}|2[0-4]\d|25[0-5])\.(\d{1}|\d{2}|[0-1]\d{2}|2[0-4]\d|25[0-5])\.(\d{1}|\d{2}|[0-1]\d{2}|2[0-4]\d|25[0-5])\.(\d{1}|\d{2}|[0-1]\d{2}|2[0-4]\d|25[0-5])$/;
    return (reVal.test (strVal));
}
function OrtSelectMove (Source, Target, Start)
{
    var nIndex;
    var eItem;
    if (Start < 0)
        Start = 0;
    nIndex = Source.selectedIndex;
    if (nIndex < Start)
        return;
    if (Target != null)
    {
        eItem = document.createElement ("OPTION");
        Target.add (eItem);
        eItem.innerText = Source.item (nIndex).text;
        eItem.value = Source.item (nIndex).value;

⌨️ 快捷键说明

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