把下面的这个做成一个js文件 然后就可以在任何页面调用了 /*================Method=======================* var_to_obj 将一个变量转换为对象* is_greater 判断是否大于某个数* is_less 判断是否小于某个数* Compare_Date 比较两个日期的大小 Num >Num return:trueNum <=Num return:false* is_numeric 判断是否是数字* is_price 判断是否是价格格式 带两位小数* Is_Null 判断是否是空true:空false:非空* IsSpace 判断是否空格* IsSpace 判断是否空格* Is_Int( 判断是否是整数true:是整数 false:不是整数* is_date 判断是否是日期* is_date 判断是否是日期* IsSelected 判断是否有有效数据被选中* isCharacter 检查是否是字符* isOtherNameCharacter 检查是否是其它可以作名称的字符* isNameCharacter 检查是否是可以作名称的字符* isEmail 检查是否是Email* isZIP 检查是否是邮编* isDigitalString 检查是否是数字字符串* IsEmpty IsEmpty函数判断一个字符串是否为空* Trim Trim函数去掉一字符串两边的空格* isDigital IsDigital函数判断一个字符串是否由数字(int or long)组成 * IsFloat IsFloat函数判断一个字符串是否由数字(int or long or float)组成 * IsTelephone 判断一个字符串是否由数字或 * () 组成 * dateTransfer 日期格式转化 / / * transferDate 转化日期 >/ / * ispassword 检查是否是密码* isLeapYear 判断是否为润年的函数* getDaysInMonth 取得每月天数的函数* jtrimstr 去掉字符串所有空格*=============================================*/
function doInputConnotEmpty(txtInput minLength sAlert){txtInput value=Trim(txtInput value)var m_IsValid=trueif(IsEmpty(txtInput value)) m_IsValid=falseif(minLength>){if(txtInput value length<minLength) m_IsValid=false}if(!m_IsValid){if(sAlert!= ) window alert(sAlert)txtInput focus()}return m_IsValid}
// 将一个变量转换为对象function var_to_obj(val){this value=val}// 判断是否大于某个数function is_greater(field crit limit){var Ret = (is_numeric(field ) ) ? (field value >limit ) : falseif (!Ret)doCritCode(field crit Value must be greater than +limit)return(Ret)}// 判断是否小于某个数function is_less(field crit limit){var Ret = (is_numeric(field ) ) ? (field value <limit ) : falseif (!Ret)doCritCode(field crit Value must be less than +limit)return(Ret)}
function is_numeric(field crit msg){var Ret = truevar NumStr= var decUsed=falsevar chrfor (i= i<field value length++i){chr=field value charAt(i)if (NumStr indexOf(chr )== ){if ( (!decUsed) &&chr== ){decUsed=true}else{Ret=false}}}if (!Ret)doCritCode(field crit msg)return(Ret)} // 判断是否是价格function is_price(field crit msg){var Ret = truevar NumStr= var decUsed=falsevar chrfor (i= i<field value length++i){chr=field value charAt(i)if (NumStr indexOf(chr )== ){if ( (!decUsed) &&chr== ){decUsed=true}else{Ret=false}}}if(Ret){if(decUsed&&(field value length field value indexOf( )<))else if(decUsed)Ret=false}if (!Ret)doCritCode(field crit msg)return(Ret)}
// 判断是否是空function is_null(field crit msg){var Text= + Trim(field value)if(Text length){ for(var i= i<Text lengthi++)if(Text charAt(i)!= &&Text charAt(i)!= )breakif(i>=Text length){Ret=true}else{Ret=false}}elseRet=trueif (Ret)doCritCode(field crit msg)return(Ret)}function IsSpace(field){var Text= +field valueif(Text length){for(var i= i<Text lengthi++)if(Text charAt(i)!= &&Text charAt(i)!= )breakif(i>=Text length)field value= }}
function doCritCode(field crit msg){if ( ( !=crit) ){alert(msg)if (crit== ){field focus()// focus does not work on certain netscape versionsfield select()}}}// 判断是否是整数function is_int(field crit msg){var Ret = truevar NumStr= var chrif (field value length== ){Ret=false}for (i= i<field value length++i){chr=field value charAt(i)if (NumStr indexOf(chr )== ){Ret=false}}if (!Ret)doCritCode(field crit msg)return(Ret)}// 判断是否是日期function is_date(field crit msg){var Ret = falsevar mark var mark var daysvar yvar mvar dif(field value== )return truecd=new Date()
if ( (mark = field value indexOf( ))== )mark =field value indexOf( )if (mark >){if ( (mark = field value indexOf( mark + )) == )mark =field value indexOf( mark + )if ((mark >)&&(mark + <field value length) ){y = parseInt(field value substring( mark ) )m = parseInt(field value substring(mark + mark ) )d = parseInt(field value substring(mark + field value length) )
year = new var_to_obj(y)month = new var_to_obj(m)day = new var_to_obj(d)days = getDaysInMonth(month value year value) +
if ((is_greater(day ))&&(is_less(day days))&&(is_greater(month ))&&(is_less(month ))&&(is_greater(year ))&&(is_less(year )))Ret=true}}if (!Ret) doCritCode(field crit msg)
return(Ret)}
function doCrit(field crit msg){if ( ( !=crit) ){alert(msg)if (crit== ){field focus()// focus does not work on certain netscape versions}}}// 判断是否有有效数据被选中function isselected(field crit msg){value= +field options[field selectedIndex] valueif(value== )Ret=falseelseRet=trueif (!Ret)doCrit(field crit msg)return(Ret)}
// 检查是否是字符// cCharacter 输入值function isCharacter( cCharacter ){var sFormat = ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
if( sFormat indexOf( cCharacter ) == ){return false}
return true}
//判断是否是数字和字母的组合function isChrandNum( cCharacter ){for(ilen= ilen<str lengthilen++){if(str charAt(ilen) <|| str charAt(ilen) >){if(str charAt(ilen) <a || str charAt(ilen) >z ){if(str charAt(ilen) <A || str charAt(ilen) >Z )return false}} }return true}
// 检查是否是其它可以作名称的字符// cCharacter 输入值function isOtherNameCharacter( cCharacter ){var sFormat = _
if( sFormat indexOf( cCharacter ) == ){return false}
return true}function isOtherNameCharacter ( cCharacter ){var sFormat =
if( sFormat indexOf( cCharacter ) == ){return false}
return true}
function isOtherNameCharacter ( cCharacter ){var sFormat =
if( sFormat indexOf( cCharacter ) == ){return false}
return true}
// 检查是否是可以作名称的字符// sValue 输入值function isNameCharacter( sValue ){if( sValue == null ){return false}
for( i = i <sValue lengthi ++ ){var cCharacter = sValue charAt( i )if( isDigital( cCharacter ) == false &&isCharacter( cCharacter ) == false &&isOtherNameCharacter( cCharacter ) == false&&isOtherNameCharacter ( cCharacter ) == false&&isOtherNameCharacter ( cCharacter ) == false ){return false}}
return true}//检查是否是密码function ispassword( sValue ){if( sValue == null ){return false}
for( i = i <sValue lengthi ++ ){var cCharacter = sValue charAt( i )if( isDigital( cCharacter ) == false &&isCharacter( cCharacter ) == false &&isOtherNameCharacter( cCharacter ) == false){return false}}
return true}
// 检查是否是Email
// sValue 输入值 合法格式为a@b c d此类形式function isEmail( sValue ){var iFirstIndex = var iSecondIndex = sValue indexOf( @ )if( iSecondIndex == ){return false}
var sTemp = sValue substring( iFirstIndex iSecondIndex )if( isNameCharacter( sTemp ) == false ){return false}
iSecondIndex = sValue indexOf( )if( iSecondIndex == || sValue substring( sValue length sValue length ) == ){return false}else if( sTemp length == sValue length ) // The last o characters are @ and {return false}else{var sTempValue = sValueiSecondIndex = sValue indexOf( @ )while( iSecondIndex != ){iFirstIndex = iSecondIndex + sTempValue = sTempValue substring( iFirstIndex sTempValue length )// The right section of valueiSecondIndex = sTempValue indexOf( )//document write( sTempValue= + sTempValue + <br>)sTemp = sTempValue substring( iSecondIndex )//document write( sTemp= + sTemp + <br>)if( isNameCharacter( sTemp ) == false ){return false}}
if( isNameCharacter( sTempValue ) == false ){return false}}
return true}
// 检查是否是邮编// sValue 输入值 合法格式为六位整数function isZIP( sValue ){if( sValue == null ){return false}
if( sValue length != ){return false}else{for( i = i <i ++ ){if( isDigital( sValue charAt( i ) ) == false ){return false}}}
return true}
// 检查是否是数字字符串// sValue 输入值function isDigitalString( sValue ){if( sValue == null ){return false}
for( i = i <sValue lengthi ++ ){if( isDigital( sValue charAt( i ) ) == false ){return false}}}
//IsEmpty函数判断一个字符串是否为空function IsEmpty(his){flag = truefor(var i= i<his lengthi++){if(his charAt(i)!= ){ flag = falsebreak}}return flag}//Trim函数去掉一字符串两边的空格function Trim(his){//找到字符串开始位置Pos_Start = for(var i= i<his lengthi++){if(his charAt(i)!= ){Pos_Start = ibreak}}//找到字符串结束位置Pos_End = for(var i=his length i>= i ){if(his charAt(i)!= ){Pos_End = ibreak}}//返回的字符串Str_Return = if(Pos_Start!= &&Pos_End!= ){ for(var i=Pos_Starti<=Pos_Endi++){Str_Return = Str_Return + his charAt(i)}}return Str_Return} //IsDigital函数判断一个字符串是否由数字(int or long)组成 function isDigital(str) {for(ilen= ilen<str lengthilen++){if(str charAt(ilen) <|| str charAt(ilen) >){return false} }return true}//IsFloat函数判断一个字符串是否由数字(int or long or float)组成 function IsFloat(str) {flag_Dec = for(ilen= ilen<str lengthilen++){if(str charAt(ilen) == ){flag_Dec++if(flag_Dec >)return falseelsecontinue} if(str charAt(ilen) <|| str charAt(ilen) >){return false} }return true}//IsTelephone函数判断一个字符串是否由数字或 * 组成 function IsTelephone(str) {for(ilen= ilen<str lengthilen++){if(str charAt(ilen) <|| str charAt(ilen) >){if((str charAt(ilen)!= )&&(str charAt(ilen)!= * ))return false} }return true}
//比较两个日期的大小 Num >Num return:trueNum <=Num return:falsefunction Compare_Date(Num Num ){var pos pos endvar para para para para para para
//para :年//para :月//para :日end=Num lengthpos =Num indexOf( )pos =Num indexOf( pos + )para =Num substring( pos )para =Num substring(pos + pos )para =Num substring(pos + end)para =parseInt(para )para =parseInt(para )para =parseInt(para )end=Num lengthpos =Num indexOf( )pos =Num indexOf( pos + )para =Num substring( pos )para =Num substring(pos + pos )para =Num substring(pos + end)para =parseInt(para )para =parseInt(para )para =parseInt(para )if(para >para ){return true}else if(para ==para ){if(para >para ){return true}else if(para ==para ){if(para >para ){return true}}}return false}
//去掉字符串所有空格function jtrimstr(str){var i= var jvar len=str lengthtrimstr= while(i<len){if(str charAt(i)!= ){trimstr=trimstr+str charAt(i)}i++}return(trimstr)}//转化日期function transferDate(str){var m= var strlen=str lengthvar n=strlen while (n>=strlen ){if(str charAt(n)== ){break}n=n }trimstr=str substring(m+ n)+ / + str substring(n+ strlen)+ / +str substring( m) return(trimstr)}
// 取得每月天数的函数//参数说明 month 月year 年// 返回值 days 天数function getDaysInMonth(month year) {var daysif (month== || month== || month== || month== || month== || month== || month== ) days= else if (month== || month== || month== || month== ) days= else if (month== ) {if (isLeapYear(year)) { days= }else { days= }}return (days)}// 判断是否为润年的函数//参数说明 Year 年份// 返回值:如果是润年 返回true 否则返回false
function isLeapYear (Year) {if (((Year % )== ) &&((Year % )!= ) || ((Year % )== )) {return (true)} else { return (false)}}
function isCharnum(str) {for(ilen= ilen<str lengthilen++){if(str charAt(ilen) <|| str charAt(ilen) >){if((str charAt(ilen)!= x ))return false} }return true}
function isCharsf(str) {for(ilen= ilen<str lengthilen++){if(str charAt(ilen) <|| str charAt(ilen) >){if(str charAt(ilen) <a || str charAt(ilen) >z )return false} }return true}
//判断一个字符串是否是由数字和 组成
function i *** onth(str) {for(ilen= ilen<str lengthilen++){if(str charAt(ilen) <|| str charAt(ilen) >){if((str charAt(ilen)!= ))return false} }return true}
lishixinzhi/Article/program/Java/Javascript/201311/25474
可以在调用之前用clearInterval()清除原来的计时器
举个栗子:
var timeTickfunction tick(){
clearInterval(timeTick);
timeTick= setInterval(function () { /*方法体*/ }, 50)
}