Javascrīpt 通用库

 

 
/*
IsEnLetter(string,string):测试字符串,大小写(UL,U,L or ul,u,l)
*/

function  IsEnLetter(objStr,size)
{
    
var reg;

    
if(Trim(objStr)==““)
    
{
        
return false;
    }

    
else
    
{
        objStr
=objStr.toString();
    }


    
if((size==null)||(Trim(size)==““))
    
{
        size
=“UL“;
    }

    
else
    
{
        size
=size.toUpperCase();
    }


    
switch(size)
    
{
        
case “UL“:
            
//大小写
            reg=/^[A-Za-z]+$/;
            
break;
        
case “U“:
            
//大写
            reg=/^[A-Z]+$/;
            
break;
        
case “L“:
            
//小写
            reg=/^[a-z]+$/;
            
break;
        
default:
            alert(“检查大小写参数,只可为(空、UL、U、L)“);
            
return false;
            
break;
    }


    
var r=objStr.match(reg);
    
if(r==null)
    
{
        
return false;
    }

    
else
    
{
        
return true;
    }

}


/*
=====================================================================
功能:鼠标小提示
作者:申旺
日期:2004/04/15
======================================================================
*/


// 定义变量、设置默认值
var  LabelFontFace = “宋体,arial,Verdana“;
var  LabelFontColor = “# 000000 “;
var  LabelFontSize = “9pt“;
var  LabelFontStyle = “Font.PLAIN“;
var  LabelBorderColor = “# 000000 “;
var  LabelBackColor = “#FFFFE1“;

// 设置各个属性
function  SetLabelFontFace(obj)
{
       ōbj
=Trim(obj);
       
if(obj==null || ōbj==““)
       
{
              obj
=“宋体,arial,Verdana“;
       }

       LabelFontFace
=obj;
}


function  SetLabelFontColor(obj)
{
    ōbj
=Trim(obj);
       
if(obj==null || ōbj==““)
       
{
              obj
=“#000000“;
       }

       LabelFontColor
=obj;
}


function  SetLabelFontSize(obj)
{
    ōbj
=Trim(obj);
       
if(obj==null || ōbj==““)
       
{
              obj
=“9pt“;
       }

       LabelFontSize
=obj;
}


function  SetLabelFontStyle(obj)
{
    ōbj
=Trim(obj);
       
if(obj==null || ōbj==““)
       
{
              obj
=“Font.PLAIN“;
       }

       LabelFontStyle
=obj;
}


function  SetLabelBorderColor(obj)
{
    ōbj
=Trim(obj);
    
if(obj==null || ōbj==““)
    
{
        obj
=“#000000“;
    }

    LabelBorderColor
=obj;
}


function  SetLabelBackColor(obj)
{
    ōbj
=Trim(obj);
    
if(obj==null || ōbj==““)
    
{
        obj
=“#FFFFE1“;
    }

    LabelBackColor
=obj;
}


// 合成文字样式
function  SetTextStyle(str)
{
    
var strRet=““;

    
var strStyle=““;

    strStyle
=“font-family:“+LabelFontFace+“;“;
    strStyle
+=“color:“+LabelFontColor+“;“;
    strStyle
+=“font-size:“+LabelFontSize+“;“;

    
switch(LabelFontStyle.toLowerCase())
    
{
        
case “font.plain“:
            strStyle
+=“font-weight: normal;“;
            strStyle
+=“font-style: normal;“;
            
break;
        
case “font.bold“:
            strStyle
+=“font-weight: bold;“;
            strStyle
+=“font-style: normal;“;
            
break;
        
case “font.italic“:
            strStyle
+=“font-weight: normal;“;
            strStyle
+=“font-style: italic;“;
            
break;
        
case “font.italicbold“:
        
case “font.bolditalic“:
            strStyle
+=“font-weight: bold;“;
            strStyle
+=“font-style: italic;“;
            
break;
        
default:
            strStyle
+=“font-weight: bold;“;
            strStyle
+=“font-style: italic;“;
            
break;
    }


    strRet
=“〈font style=’“+strStyle+“’〉“;
    strRet
+=“ “+str+“ “;
    strRet
+=“〈/font〉“;

    
return strRet;
}


// 合成表格样式
function  SetTableStyle()
{
    
var strRet=““;

    strRet
+=“border-right: “+LabelBorderColor+“ 1px solid;“;
    strRet
+=“border-top: “+LabelBorderColor+“ 1px solid;“;
    strRet
+=“border-left: “+LabelBorderColor+“ 1px solid;“;
    strRet
+=“border-bottom: “+LabelBorderColor+“ 1px solid;“;
    strRet
+=“background-color:“+LabelBackColor;

    
return strRet;
}


// 显示提示
function  ShowNote(str)
{
       
var strHtml;

       strHtml
=““;
       strHtml
+=“〈table height=1px width=1px border=0’cellspacing=0’ cellpadding=0’ style=’“ + SetTableStyle() + “’〉“;
       strHtml
+=“〈tr〉“;
       strHtml
+=“〈td〉“+SetTextStyle(str)+“〈/td〉“;
       strHtml
+=“〈/tr〉“;
       strHtml
+=“〈/table〉“;

       
if (document.all&&document.readyState==“complete“)
       
{
              document.all.div_Note.innerHTML
=strHtml;
              document.all.div_Note.style.pixelLeft
=event.clientX+document.body.scrollLeft+10
              document.all.div_Note.style.pixelTop
=event.clientY+document.body.scrollTop+10
              document.all.div_Note.style.visibility
=“visible“
       }

}


// 隐藏提示
function  HideNote()
{
       
if (document.all)
       
{
              document.all.div_Note.style.visibility
=“hidden“;
       }

       
else
       
{
              
if (document.layers)
              
{
                     clearInterval(currentscroll)
                     document.div_Note.visibility
=“hidden“;
              }

       }

}


// 初始化
function  Init()
{
    window.document.write(“〈div id
=“div_Note“ style=“VISIBILITY:hidden; POSITION:absolute; HEIGHT:13px;z-index:1“〉〈/div〉“);
}

Init();

// 生成提示字符
function  ShowLabel(text,note,bclick)
{
       
if(bclick!=null)
       
{
              
return “〈a href=“#“ ōnMouseOver=“ShowNote(’“ + note + “’)“ ōnMouseOut=“HideNote()“ ōnClick=“javascrīptoSomeThing(this);“〉“ + text + “〈/a〉“;
       }

       
else
       
{
           
return “〈a href=“#“ ōnMouseOver=“ShowNote(’“ + note + “’)“ ōnMouseOut=“HideNote()“〉“ + text + “〈/a〉“;
       }

}


测试页面:
〈HTML〉
    〈HEAD〉
        〈title〉Common javascrīpt〈
/ title〉
              〈scrīpt language
= “javascrīpt“ src = “. / Common.js“〉〈 / scrīpt〉
        〈scrīpt language
= “javascrīpt“〉
                     
function  CheckInt()
                     
{
                            iptResult.value
=IsInt(iptTest.value,iptSign.value,iptZero.value);
                     }


                     
function  CheckFloat()
                     
{
                            iptResult.value
=IsFloat(iptTest.value,iptSign.value,iptZero.value);
                     }


                     
function  CheckLetter()
                     
{
                            iptResult.value
=IsEnLetter(iptTest.value,iptSign.value);
                     }

                     document.write(ShowLabel(“TEST“,“Only a testing
! “));
                     document.write(“〈br〉“);
              〈
/ scrīpt〉
        〈meta http
- equiv = “expires“ content = 0 “〉
    〈
/ HEAD〉
    〈body〉
     〈input type
= text value = ““ id = “iptTest“〉〈input type = button value = “IsEmpty“ ōnclick = “IsEmpty(’iptTest’);“〉
     〈input type
= button value = “CheckInt“ ōnclick = “CheckInt()“〉
        〈br〉
     〈input type
= text value = ““ id = “iptSign“ NAME = “iptSign“〉〈input type = button value = “CheckFloat“ ōnclick = “CheckFloat()“〉
        〈br〉
     〈input type
= text value = ““ id = “iptZero“ NAME = “iptZero“〉〈input type = button value = “CheckLetter“ ōnclick = “CheckLetter()“〉
     〈br〉
     〈input type
= text value = ““ id = iptResult disabled = true
    〈
/ body〉
/ HTML〉 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值