posts - 5,  comments - 5,  trackbacks - 0

// 根据检索项设置下拉框选择项

function control_selectedIndex(select_object,select_item)

{

         for(i=0;i<select_object.options.length;i++){

                   if(select_object.options(i).value == select_item){

                            select_object.selectedIndex = i ;

                            break;

                   }

         }

}

// 检查日期是否合法

function check_Date(input, pattern) {

         var right_chars = "0123456789"+pattern;

         for(var i=0; i < input.length; i++){

         if(right_chars.indexOf(input.charAt(i)) == -1)

             return false;

         }

 

         var pos1 = input.indexOf(pattern);

         var pos2 = input.lastIndexOf(pattern);

         if (pos1 == -1) {

                   return false;

         } else if (pos1 != -1 && pos1 == pos2) {

                   return false;

         }

         var yyyy = parseInt(input.substring(0, pos1), 10);

         var mm = parseInt(input.substring(pos1+1, pos2), 10);

         var dd = parseInt(input.substring(pos2+1, input.length), 10);

 

         if (isNaN(yyyy) || isNaN(mm) || isNaN(dd)) {

                   return false;

         }

 

         if (mm < 1 || mm > 12) {

                   return false;

         }

 

         var maxDay = 30;      // 缺省为小月

         if (mm == 2) {

                   if ((yyyy%4) == 0) {     //(4 的倍数但不是 100 的倍数 或者 (4 的倍数, 100 的倍数, 400 的倍数 )

                            if ((yyyy%100) == 0) {

                                     if ((yyyy%400) == 0) {

                                               maxday = 29;    // 闰月

                                     }

                                     else {

                                               maxDay = 28;   // 平月

                                     }

                            }

                            else {

                                     maxDay = 29;   // 闰月

                            }

                   }

                   else {

                            maxDay = 28;   // 平月

                   }

         }

         // 大月

         else if (mm == 1 || mm == 3 || mm == 5 || mm == 7 || mm == 8 || mm == 10 || mm == 12) {

                   maxDay = 31;

         }

 

         if (dd < 1 || dd > maxDay) {

                   return false;

         }

 

         return true;

}

 

// 检查输入是否为数字

/*function isNumber() {

         var fNum = 0 ;

         var num = "0123456789"+".";

         var sNum = event.srcElement.value ;

         for(var i=0; i < sNum.length; i++){

                   if(num.indexOf(sNum.charAt(i)) == -1)

                   {

                            alert(" 输入数据不合法 !");

                            event.srcElement.focus();

                            return false;

                   }

                   if(sNum.charAt(i)=="."){

                            fNum++ ;

                   }

         }

         if(fNum > 1){

                   alert(" 小数点位置不合法 !");

                   event.srcElement.focus();

                   return false;

         }

         return true;

}*/

 

// 得到字符串长度

function getStringLength(sParam){

         var iNum = sParam.length ;

         var sTmp ;

         var iReturn = 0 ;

         if(sParam==null || sParam == ""){

                   return iReturn ;

         }

         for(var i=0;i<iNum;i++){

                   sTmp = sParam.substring(i,i+1);

                   if (/[^\x00-\xff]/g.test(sTmp)){

                            iReturn += 2 ;

                   }else{

                            iReturn += 1 ;

                   }

         }

         return iReturn ;

}

 

// 判断 TextArea

function checkTextArea(areaName)

{

         if(getStringLength(areaName.value)>areaName.MaxLen)

         {                

                   alert(areaName.Caption+" 最多只能输入 "+areaName.MaxLen+" 字符。 ");

                   areaName.focus();

                   areaName.select();

                   return false;

         }

         else

                   return true;

}

 

/*

         函数名称: trim

         函数功能 : 去除字符串头部和尾部的空格

         传入参数:字符串变量

         传出结果:处理后的子串

*/

function trim(str){

         return str.replace(/(^\s*)|(\s*$)/g, "");

}

 

/*  函数功能:判断传入参数是否为 yyyy-mm-dd

                              yyyy/mm/dd 格式的正确日期

                              2001/01/2 2001-3-04 也是允许的格式

                              如果是,则返回一个对应的日期对象

                              如果否,则返回 false

*/

function isDate(strDate){

         var regYear = /\d{4}[-/]/g;    //year pattern

         var regMonth;                     

         var regDay =  /\d{1,2}/g;;

         var chrSeperator;

         var arr,str;

         if ((arr = regYear.exec(strDate)) == null)

                   return false;

         var intYearlen = arr.lastIndex - arr.index - 1;

         if (arr.index != 0 || (intYearlen != 4 && intYearlen != 2))

                   return false;

         str = arr[0];

         chrSeperator = str.charAt(str.length - 1);  // get the seperator ('-' or '/')

         intYear = parseInt(str.substr(0, str.length - 1));  // get the year

         if (intYear < 1900 || intYear > 2099)  //Error Year

                   return false;

 

         strDate = strDate.substr(arr.lastIndex);

         if (chrSeperator == "-")

                   regMonth = /\d{1,2}[-]/g;

         else

                   regMonth = /\d{1,2}[/]/g;

         if ((arr = regMonth.exec(strDate)) == null)

                   return false;

         if (arr.index != 0)

                   return false;

         str = arr[0];

         if (str.charAt(0) == '0') {

                   intMonth = parseInt(str.substr(1, str.length - 2)); // get the month

         } else {

                   intMonth = parseInt(str.substr(0, str.length - 1)); // get the month

         }

         if (intMonth < 1 || intMonth > 12) //Error Month

                   return false;

 

         strDate = strDate.substr(arr.lastIndex);

 

         if ((arr = regDay.exec(strDate)) == null)

                   return false;

         if (arr.index != 0 || arr.lastIndex != strDate.length)

                   return false;

         str = arr[0];

         if (str.charAt(0) == '0') {

                   intDay = parseInt(str.substr(1, str.length - 1)); // get the day

         } else {

                   intDay = parseInt(str); // get the day

         }       

         if (intDay < 1 || intDay > 31)  //Error Day

                   return false;

 

         datDate = new Date(intYear, intMonth - 1, intDay); //Test the Date

         if (isNaN(datDate))  //Error Date Format

                   return false;

         if (datDate.getMonth() != intMonth - 1 || datDate.getDate() != intDay)  //invalid date such as '1999/02/29' and '1999/04/31'

                   return false;

         return datDate;  //Return the Date in parsed format

}

 

 

/*

         函数名称: isint

         函数功能 : 判断是否整数

*/

function isInt(n) {

         var i = parseInt(n);

         if (i == NaN) {

                   return false;

         }

         if (i != n * 1){

                   return false;

         }

         return true;

}

 

/*

         函数名称: isDecimal

         函数功能 : 判断是否小数

*/

function isDecimal(str,f,n) {

    var p=str.indexOf(".");

    var int,flt;

    if (p<0) { p=str.length ;}

    int=str.substr(0,p);

    flt=str.substr(p+1);

    if (isInt(int)==false) {

       return false;

    }

    if (flt!='') {

       if (isInt(flt)==false) {

          return false;

       }

    }

    if ((int.length > f-n) || (flt.length > n)) {

       return false;

    }

    return true;

}

 

/*

         函数功能 : 判断是否正确邮件形式

*/

function isMail(str) {

    var a=str.indexOf("@")+1;

    var p=str.indexOf(".")+1;

    if(str.indexOf("'") > 0)

                   return false;

         if(str.indexOf('"') > 0)

                   return false;

    if (a<2)

       return false;   

    if (p<1)

       return false;   

    if (p<a+2)

       return false;   

    if (str.length==p)

       return false;          

    return true;

}

 

/*

         函数功能 : 判断是否浮点数

*/

function isFloat(str) {

         var ch=str.charAt(0);

         if( ch == "." ) return false;

    for (var i=0; i < str.length; i++)

         {        ch=str.charAt(i);

                   if ((ch != ".") && (ch != "0") && (ch != "1") && (ch != "2") && (ch != "3") && (ch != "4") && (ch != "5") && (ch != "6") && (ch != "7") && (ch != "8") && (ch != "9"))  

                            return false;

         }

    return true;

}

 

/*

         函数功能 : 判断是否数字

*/

function isNumber(str) {

    for (var i=0; i < str.length; i++)

         {        var ch=str.charAt(i);

                   if ((ch != "0") && (ch != "1") && (ch != "2") && (ch != "3") && (ch != "4") && (ch != "5") && (ch != "6") && (ch != "7") && (ch != "8") && (ch != "9"))        

                            return false;

         }

    return true;

}

 

/*

         函数功能 : 判断是否电话号码形式

*/

function isPhone(str){

         var intIndex;

         var intCharCount;

         for(intIndex = 0; intIndex < str.length; intIndex++){

                   if(str.charCodeAt(intIndex) < 32)

                            return false;

                   if(str.charCodeAt(intIndex) == 34)

                            return false;

                   if(str.charCodeAt(intIndex) == 39)

                            return false;

                   if(str.charCodeAt(intIndex) > 126)

                            return false;

         }

         return true;

}

 

/*

         函数名称: checkString()

         函数功能 : 不能包含 & 、’、”、 < > : ; 等特殊字符 ;

                   合法字符: 32 (空格)、 48~57 (数字)、 65~90 (大写字符)、 95 (下划线)、 97~122 (小写字符)、 >127 (汉字)。

         创建时间: 2001/06/14

         传入参数:字符串变量

         传出结果:处理后的子串

*/

function checkString(str){

         var strChar = str;

         var isValid = true;

         for (var i = 0; i < str.length; i++){

                   if ( (str.charCodeAt(i) == 32) || ((str.charCodeAt(i) >= 48) && (str.charCodeAt(i) <= 57)) || ((str.charCodeAt(i) >= 65) && (str.charCodeAt(i) <= 90)) || (str.charCodeAt(i) == 95) || ((str.charCodeAt(i) >= 97) && (str.charCodeAt(i) <= 122)) || (str.charCodeAt(i) > 127) ) {

                            // do nothing                                 

                   } else {

                            isValid = false;

                            break;

                   }

         }

         return isValid;

}

 

// 禁止鼠标右键功能 ,RightMouseDownFun 函数名(处理右键功能)

//document.onmousedown=CancelRightMouseDown;

function CancelRightMouseDown()

{

     if(event.button==2)

                   {       

                            if(!window.RightMouseDownFun){// 如果不存在右键事件处理函数,禁止右键快捷菜单

                                     //alert(location.href);// 测试用

                                     //location.reload();

                                     document.oncontextmenu=Function("return false;");

                            }

                            else RightMouseDownFun();

                   }

}

 

// 窗口最大化

function window.onfocus(){

         var Pass=true;

         var inputPass="";

         var str="";

         if(!top.window.IfFullScr&&top.window.SetScrMax){

                   if(top.window.ScrPass!=""){

                            Pass=false;

                            while(!Pass&&inputPass!==null){

                                      inputPass=prompt(" 请输入正确密码解开锁定 "+str,"");

                                     Pass=(inputPass==top.window.ScrPass);

                                     if(!Pass) str=" ,密码错误! ";

                            }

                   }

                   else Pass=confirm(" 将窗口最大化? ");

                   if(Pass) top.window.SetScrMax();

                   else top.window.SetScrMin();

         }

}

 

function document.onkeydown(){// F1 调出使用帮助

         var Key;

         Key=event.keyCode;

        

         if(Key=="113"){// F2 显示桌面

                   top.mainFrame.location.href="/Desktop.asp";

                   return false;

         }

         return true;

}

 

/**********************************************************************************

                                                                           列表项目处理函数集

选择下拉列表项目

obj             列表对象

value         目标项目值

*/

function OptionSelect(obj,value){

         var flags=false;

         var i;

         //alert("hello");

         obj=eval(obj);

         for (i=0;flags||i<obj.options.length ;i++ )

         {

                   if (obj.options[i].value==value)

                   {

                            obj.options[i].selected=true;

                            flags=true;

                   }

         }

}

// 把已选择的项目,从一个列表移至另外一个列表 , 并删除选择项

function SelectMove(obj1,obj2){

         var sOption;

         for(var i=0;i<obj1.length;){

                   if(obj1[i].selected){

                            sOption=new Option(obj1[i].text,obj1[i].value);

                            obj2.add(sOption);

                            obj1.remove(i);

                   }

                   else i++;

         }

}

 

// 转移所有项目

function SelectMoveAll(obj1,obj2){

         SelectAll(obj1);

         SelectMove(obj1,obj2);

}

 

// 把列表中所有项目标记为选择状态

function SelectAll(obj){

         for (var i=0;i<obj.length ;i++ )

         {

                   obj[i].selected=true;

         }

}

 

function AddOption(InputName, ListName)

{

         var val = document.all(InputName).value;

         if (val == "") return;

         var bFound=false;

         var List = document.all(ListName);

         var ListLen = List.options.length;

         if( ListLen > 0)

         {

                   for(i = 0; i < ListLen; i++)

                   {

                            if( List.options(i).value == val )

                            {

                                     bFound=true;

                                     break;

                            }

                   }

         }

         if(!bFound)

         {

                   var oOption=document.createElement("OPTION");

                   oOption.text=val;

                   oOption.value=val;

                   List.add(oOption);

         }

}

 

function AddOptionItemTest(SourceListName, DestListName)

{

         var SourceList = document.all(SourceListName);

         var bFound;

         var List = document.all(DestListName);

         var ListLen;

         var SourceListLen = SourceList.options.length;

         var DestListLen=List.options.length;

         var OptionArrayText =new Array();

         var OptionArrayValue=new Array();

        

         for(j=0;j<DestListLen;j++)          {

                   OptionArrayText(j)=List.options(j).text;

                   OptionArrayValue(j)=List.options(j).value;

         }

         for (j=SourceListLen-1; j>=0; j--)

           if (SourceList.options(j).selected) {

                   val = SourceList.options(j).value;

                   text = SourceList.options(j).text;

                   ListLen = List.options.length;

                   bFound = false;

                   if( ListLen > 0)

                   {

                            for(i = 0; i < ListLen; i++)

                            {

                                     if( OptionArrayValue(i) == val )

                                     {

                                               bFound=true;

                                               break;

                                     }

                            }

                   }

                   if(!bFound)

                   {

                            var oOption=document.createElement("OPTION");

                            oOption.text=text;

                            oOption.value=val;

                            List.add(oOption);

                            SourceList.remove(j);

                   }

         }

}

 

function AddOptionItem(SourceListName, DestListName)

{

         var SourceList = document.all(SourceListName);

         var bFound;

         var List = document.all(DestListName);

         var ListLen;

         var SourceListLen = SourceList.options.length;

        

        

         for (j=SourceListLen-1; j>=0; j--)

           if (SourceList.options(j).selected) {

                   val = SourceList.options(j).value;

                   text = SourceList.options(j).text;

                   ListLen = List.options.length;

                   bFound = false;

                   if( ListLen > 0)

                   {

                            for(i = 0; i < ListLen; i++)

                            {

                                     if( List.options(i).value == val )

                                     {

                                               bFound=true;

                                               break;

                                     }

                            }

                   }

                   if(!bFound)

                   {

                            var oOption=document.createElement("OPTION");

                            oOption.text=text;

                            oOption.value=val;

                            List.add(oOption);

                            SourceList.remove(j);

                   }

         }

}

function DelOption(ListName)

{

         var List = document.all(ListName);

         var ListLen = List.options.length;

         for(i = ListLen - 1; i >= 0; i--)

         {

                   if( List.options(i).selected )

                   {

                            List.remove(i);

                   }

         }

}

 

function DelAllOption(ListName)

{

         var List = document.all(ListName);

         var ListLen = List.options.length;

         for(i = ListLen - 1; i >= 0; i--)

         {

                   List.remove(i);

         }

}

/*************************************************************************************/

// 打开一个非模态窗口

function PopUpDlg(FileName,WINname,WINwidth,WINheight){

        

         var features =

                   'dialogWidth:'  + WINwidth  + 'px;' +

                   'dialogHeight:' + WINheight + 'px;' +

                   'directories:no; localtion:no; menubar:no; status=no; toolbar=no;scrollbars:yes;Resizeable=no;help=no';

                  

         //window.showModalDialog(FileName, WINname , features );

         window.showModelessDialog(FileName, WINname , features );

        

}

 

// 数据验证:是否为空

function isNull(value){

         if(value=="") return true;

         if(value.match("\\S")==null) return true;

         return false;

}

 

// 判断是否正确的 E-mail 格式

function isMail(value){

         if( value.match("\\w{1,}@\\w{1,}.\\w{1,}")!=null) return true;

         else return false;

}

 

// 判断是否整数

function isInt(value){

         if(value.match("\\D")==null) return true;

         else return false;

}

 

// 判断是否数字

function isNumber(value){

         if(!isNaN(value)) return true;

         else return false;

}

 

// 清除左空格

function LTrim(value){

         if(isNull(value)) return "";

         return value.substring(value.indexOf(" "),value.length-1);

}

 

// 清除右空格

function RTrim(value){

         if(isNull(value)) return "";

 

}

 

// 判断是否包含特殊字符

function incSpecialChar(value){

         if(value.match("`~!@#$%^&*()+-=|\\/")!=null) return true;

         else return false;

}

 

// 比较两日期对象的大小

function compareTimeObj(sDateObj,eDateObj)

{

// 两日期对象的格式要求是: 1 、必须一致, 2 yyyy-MM-dd

         var r = sDateObj.value.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);

  if(r==null)return false;

  var sDate= new Date(r[1], r[3]-1, r[4]);

        

         r = eDateObj.value.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);

  if(r==null)return false;

  var eDate= new Date(r[1], r[3]-1, r[4]);

        

         if(sDateObj.value > eDateObj.value) return 1;

         else if(sDateObj.value == eDateObj.value) return 0;

         else  return -1;

}

 

// 比较两日期对象的大小

function compareObj(sDateObj,eDateObj)

{

         // 两日期对象的格式要求是: 1 、必须一致, 2 yyyy-MM-dd hh:mi:ss

         var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;

         var r = sDateObj.value.match(reg);

         var sDate= new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]);

         r = eDateObj.value.match(reg);

         var eDate= new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]);

        

         if(sDateObj.value > eDateObj.value) return 1;

         else if(sDateObj.value == eDateObj.value) return 0;

         else  return -1;

}

//求两段时间的差
function diffTimeObj(sDateObj,eDateObj)
 {
          var oldtimestr=sDateObj.value;
          var oldlist = oldtimestr.split('-');
          var oldtime = new Date(oldlist[0],oldlist[1],oldlist[2]); 
          var newtimestr=eDateObj.value;
          var newlist = newtimestr.split('-');
          var newtime = new Date(newlist[0],newlist[1],newlist[2]);

          var diff_s = newtime - oldtime;
          var diff_d = (((diff_s/1000)/60)/60)/24;
          if(diff_d > document.all.diffmonth.value*30)
           {
                     return 1;
           }
           else
            {
                      return 0;
            }
}


//window.open输出内容
 function openNewWind ()
  {
     newWind = window.open('','','height=250,width=750');
     setTimeout('loadContext()',100);
 }

function 'loadContext()
 {
     var output='';
     output+='<html><head><title>....</title></head><body>';
     output+='<table style=font:12px><tr><td>';
     output+=document.all.the_help.value;
     output+='</td></tr></table>';  
     output+='</body></html>';
     newWind.document.write(output);
     newWind.document.close();
}

posted on 2006-11-21 19:48 曾科 阅读(327) 评论(0)  编辑  收藏 所属分类: JavaScript

只有注册用户登录后才能发表评论。


网站导航:
 
<2024年12月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

常用链接

留言簿(3)

随笔档案

文章分类

文章档案

相册

.net

搜索

  •  

最新评论

阅读排行榜

评论排行榜