Java script 正则表达式(7)

来源:互联网 发布:c语言2的n次方 编辑:程序博客网 时间:2024/05/16 06:32
/*判断当前对象是否可见*/
代码
function isVisible(obj){
    var visAtt,disAtt;
    try{
        disAtt=obj.style.display;
        visAtt=obj.style.visibility;
    }catch(e){}
    if(disAtt=="none" || visAtt=="hidden")
        return false;
    return true;
}
/*判断当前对象及其父对象是否可见*/
代码
function checkPrVis(obj){
    var pr=obj.parentNode;
    do{
        if(pr == undefined || pr == "undefined") return true;
        else{
            if(!isVisible(pr)) return false;
        }
    }while(pr=pr.parentNode);
    return true;
}
/* 弹出警告对话框,用户点确定后将光标置于出错文本框上, 并且将原来输入内容选中。*/
代码
function f_alert(obj,alertInfo)
{
    var caption = obj.getAttribute("eos_displayname");
    if(caption == null)
        caption = "";
    alert(caption + ":" + alertInfo + "!");
    obj.select();
    if(isVisible(obj) && checkPrVis(obj))
        obj.focus();
}
/** * 检测字符串是否为空 */
代码
function isnull(str)
{
    var i;
    if(str.length == 0)
        return true;
    for (i=0;i<str.length;i++)
    {
        if (str.charAt(i)!=' ')
            return false;
    }
    return true;
}
/** * 检测指定文本框输入是否合法。
* 如果用户输入的内容有错,则弹出提示对话框,
* 同时将焦点置于该文本框上,并且该文本框前面
* 会出现一个警告图标(输入正确后会自动去掉)。 */
代码
function checkInput(object)
{
    var image;
    var i;
    var length;

    if(object.eos_maxsize + "" != "undefined") length = object.eos_maxsize;
    else length = 0;

    if (object.eos_isnull=="true" && isnull(object.value))  return true;

    /* 长度校验 */
    if(length != 0 && strlen(object.value) > parseInt(length)) {
            f_alert(object, "超出最大长度" + length);
            return false;
    }
    /* 数据类型校验 */
    else {
        if (object.eos_datatype + "" != "undefined")
        {

            var dtype = object.eos_datatype;
            var objName = object.name;
            //如果类型名后面带有括号,则视括号前面的字符串为校验类型
            if(dtype.indexOf("(") != -1)
                dtype = dtype.substring(0,dtype.indexOf("("));
            //根据页面元素的校验类型进行校验
            try{
                if(eval("f_check_" + dtype + "(object)") != true)
                    return false;
            }catch(e){return true;}
            /*  如果form中存在name前半部分相同,并且同时存在以"min"和"max"结尾的表单域,
                那么视为按区间查询。即"min"结尾的表单域的值要小于等于"max"结尾的表单域的值。 */
            if(objName.substring((objName.length-3),objName.length)=="min")
            {
                var objMaxName = objName.substring(0, (objName.length-3)) + "max";
                if(document.getElementById(objMaxName) != undefined && document.getElementById(objMaxName) != "undefined" )
                {
                    if(checkIntervalObjs(object, document.getElementById(objMaxName)) != true)
                        return false;
                }
            }
        }
    }
    return true;
}

原创粉丝点击