当前位置:   article > 正文

js脚本使用大全

js脚本

//页面里回车到下一控件的焦点

οnclick="DataGridSelectRowSetAllCheck('DataGridList','chkSelectItem',this);"


//设置所有selectRow
function DataGridSelectRowSetAllCheck(sDGName,sCheckName,objCheck)
{
    for (var i=0;i<document.forms[0].elements.length;i++)
 {
  var e = document.forms[0].elements[i];
  if ( (e.type=='checkbox') )
  {               
   if(!e.disabled){
    if(e.name.lastIndexOf(sCheckName)!=-1 && e.name.lastIndexOf(sDGName)!=-1)
    {
     e.checked = objCheck.checked;
    }
   }
  }
 }
}


function Enter2Tab(e)
...{
        try
        ...{
                var ob = IsFireFox ? e.target : event.srcElement;
                if(ob.tagName == "INPUT" &&
                (
                ob.type == "text"     ||
                ob.type == "password" ||
                ob.type == "checkbox" ||
                ob.type == "radio"
                )   ||
                ob.tagName == "SELECT")
                ...{
                        var key = IsFireFox ? e.which : event.keyCode;
                        if (key == 13)
                        ...{
                                if (IsFireFox)
                                ...{
                                        event.which = 9;
                                }
                                else
                                ...{
                                        event.keyCode = 9;
                                }
                        }
                }
        }
        catch(E)...{}
}
//打开此功能请取消下行注释
//document.onkeydown = Enter2Tab;

//ajax对象创建
function AjaxLib()
...{
        var objXMLHttp;
        if (window.XMLHttpRequest)
        ...{
                objXMLHttp = new XMLHttpRequest();
        }
        else
        ...{
                //使用该代码,出现问题 var MSXML = ['MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];
                var MSXML = ['MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];
                for(var n = 0; n < MSXML.length; n ++)
                ...{
                        try
                        ...{
                                objXMLHttp = new ActiveXObject(MSXML[n]);       
                                break;
                        }
                        catch(e)
                        ...{
                        }
                }
                if (!objXMLHttp && typeof XMLHttpRequest != 'undefined')
                ...{
                        objXMLHttp = new XMLHttpRequest();
                }
        }
        return objXMLHttp;
}

//判断用户名是否符合标准
function UserNameIsOk(ssn)
...{
        var re = /^[0-9a-z][w-.]*[0-9a-z]$/i;
        return re.test(ssn) ? true : false;
}

//_______全选择__________
function SelectAll()
...{
    var empty;
        var f = document.forms[0];
    for (var i = 0; i < f.length; i++)
    ...{
        empty = f[i];
        if (empty.type == "checkbox" && empty.disabled == false)
            empty.checked = true;
    }
}

//__________返选择_________
function SelectReverse()
...{
    var empty;
        var f = document.forms[0];
    for (var i = 0; i < f.length; i++)
    ...{
        empty = f[i];
        if (empty.type == "checkbox" && empty.disabled == false)
                if(empty.checked == true)
                ...{
                   empty.checked = false;
                }
                else
                ...{
                   empty.checked = true;
                }
    }
}

//提交查询内容 submit search find content
function GoPage(pn)
...{
        try
        ...{
                document.forms[0].page.value = pn;
                document.forms[0].submit();
        }
        catch(E)
        ...{
                document.forms[1].page.value = pn;
                document.forms[1].submit();
        }
}

function WoodsAlert(ob, tip)
...{
        alert(tip);
        //ob.value = "";
        ob.focus();
}

//__________处理特殊字符________________
function invalid_keyword()
...{
    var keyword = new Array("<", ">", "%", "'", """);
    var f, ob;
    for (var form = 0; form < document.forms.length; form++)
    ...{
        f = document.forms[form];
        for (var i = 0; i < f.length; i++)
        ...{
            ob = f[i];
            if (ob.type == "text" && ob.disabled == false)
            ...{
               for (j = 0; j < keyword.length; j++)
               ...{
                    if (ob.value.indexOf(keyword[j]) != -1)
                    ...{
                        alert("在输入框聚焦处发现非法字符[" + keyword[j] + "]。");
                        //ob.value = "";
                        ob.focus();
                        return false;
                    }
               }
               ob.value = Trim(ob.value);
            }
        }
    }
    return true;
}
function IsTime(str)
//__________判断是否为时间字符串________________________
...{
        var a = str.match(/^(d...{1,2})(:)?(d...{1,2})2(d...{1,2})$/);
        if (a == null) ...{alert('输入的参数不是时间格式'); return false;}
        if (a[1]>24 || a[3]>60 || a[4]>60)
        ...{
          return false
        }
        return true;
}

function IsDate(str)
//_________是否为日期(YYYY-MM-DD)类型字符串_________________________
...{
        var r = str.match(/^(d...{1,4})(-|/)(d...{1,2})2(d...{1,2})$/);
        if (r == null) return false;
        var d = new Date(r[1], r[3]-1, r[4]);
        return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]);
}

function IsBigCurrentDate(str)
//_________________判断用户给出的日期是否大于当前日期______________________________
...{
        var today = new Date();
        var tY = String(today.getFullYear());
        var tM = String(today.getMonth() + 1);
        (tM.length <= 1) ? tM = "0" + tM : tM = tM;

        var tD = String(today.getDate());
        (tD.length <= 1) ? tD = "0" + tD : tD = tD;

        var tH = String(today.getHours());
        (tH.length <= 1) ? tH = "0" + tH : tH = tH;

        var tM1 = String(today.getMinutes());
        (tM1.length <= 1) ? tM1 = "0" + tM1 : tM1 = tM1;

        var tdate = tY + "-" + tM + "-" + tD + " " + tH + ":" + tM1 + ":59";//zhuweisong 添加秒的叛断
        if (str > tdate)
        ...{
                return true;
        }
        else
        ...{
                return false;
        }
}

function IsDateTime(str)
//____________是否为时间日期类型__________________________________
...{
        var reg = /^(d...{1,4})(-|/)(d...{1,2})2(d...{1,2}) (d...{1,2}):(d...{1,2}):(d...{1,2})$/;
        var r = str.match(reg);
        if (r == null) return false;
        var d= new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]);
        return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]&&d.getHours()==r[5]&&d.getMinutes()==r[6]&&d.getSeconds()==r[7]);
}

function IsEmail(mail)
//_____________判断是否是有效的EMAIL地址________________________________
...{
        return(new RegExp(/^w+((-w+)|(.w+))*@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+)*.[A-Za-z0-9]+$/).test(mail));
}

function IsIp(s)
//________________判断是否为有效IP地址_________________________________
...{
        var check = function(v)
        ...{
                try
                ...{
                        return (v <= 255 && v >= 0);
                }
                catch(x)
                ...{
                        return false;
                }
        }
        var re = s.split(".")
        return (re.length==4)?(check(re[0]) && check(re[1]) && check(re[2]) && check(re[3])):false
}


//_________判断输入的是否为汉字___________begin__________
function isCharsInBag (s, bag)
...{
        var i,c;
        for (i = 0; i < s.length; i++)
        ...{
                c = s.charAt(i);//字符串s中的字符
                if (bag.indexOf(c) > -1)
                return c;
        }
        return "";
}

function IsCn(s)
...{
        var errorChar;
        var badChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789><,[]{}?/+=|'":;~!#$%()`";
        errorChar = isCharsInBag(s, badChar)
        if (errorChar != "" )
        ...{
                return false;
        }
        return true;
}
//_________判断输入的是否为汉字___________end__________

//________函数功能:判断输入的字符串是不是英文__________begin___________
function isCharsInBagEn (s, bag)
...{
        var i,c;
        for (i = 0; i < s.length; i++)
        ...{
                c = s.charAt(i);//字符串s中的字符
                if (bag.indexOf(c) <0)
                return c;
        }
        return "";
}

function IsEn(s)
...{
        var errorChar;
        var badChar = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
        errorChar = isCharsInBagEn(s, badChar)
        return (errorChar != "" ) ? false : true;
}
//________函数功能:判断输入的字符串是不是英文__________end___________

/**//********************
函数名称:IsTelephone
函数功能:固话,手机号码检查函数,合法返回true,反之,返回false
函数参数:obj,待检查的号码
检查规则:
  (1)电话号码由数字、"("、")"和"-"构成
  (2)电话号码为3到8位
  (3)如果电话号码中包含有区号,那么区号为三位或四位
  (4)区号用"("、")"或"-"和其他部分隔开
  (5)移动电话号码为11或12位,如果为12位,那么第一位为0
  (6)11位移动电话号码的第一位和第二位为"13"
  (7)12位移动电话号码的第二位和第三位为"13"
********************/
function IsTelephone(obj)
...{
        var pattern=/(^([0+]d...{2,3})d...{3,4}-d...{3,8}$)|(^([0+]d...{2,3})d...{3,4}d...{3,8}$)|(^([0+]d...{2,3})...{0,1}13d...{9}$)|(^d...{3,4}d...{3,8}$)|(^d...{3,4}-d...{3,8}$)/;
        return (pattern.test(obj)) ? true : false;
}

/**//********************
函数名称:IsLegality
函数功能:检查字符串的合法性,即是否包含" '字符,包含则返回false;反之返回true
函数参数:obj,需要检测的字符串
********************/
function IsLegality(obj)
...{
        var intCount1 = obj.indexOf(""",0);
        var intCount2 = obj.indexOf("'",0);
        return (intCount1 > 0 || intCount2 > 0) ? false : true;
}

/**//********************
函数名称:IsNumber
函数功能:检测字符串是否全为数字
函数参数:str,需要检测的字符串
********************/
function IsNumber(str)
...{
        var number_chars = "1234567890";
        var i;
        for (i = 0; i < str.length; i++)
        ...{
                if (number_chars.indexOf(str.charAt(i))==-1) return false;
        }
        return true;
}

/**//********************
函数名称:Trim
函数功能:去除字符串两边的空格
函数参数:str,需要处理的字符串
********************/
function Trim(str)
...{
        return str.replace(/(^s*)|(s*$)/g, "");
}

/**//********************
函数名称:LTrim
函数功能:去除左边的空格
函数参数:str,需要处理的字符串
********************/
function LTrim(str)
...{
        return str.replace(/(^s*)/g, "");
}

/**//********************
函数名称:RTrim
函数功能:去除右边的空格
函数参数:str,需要处理的字符串
********************/
function RTrim(str)
...{
        return this.replace(/(s*$)/g, "");
}

/**//********************
函数名称:IsNull
函数功能:判断给定字符串是否为空
函数参数:str,需要处理的字符串
********************/
function IsNull(str)
...{
        return (Trim(str) == "") ? false : true;
}

//获取cookie
function getCookie(name)
...{
        var search = name + "="
        if(document.cookie.length > 0)
        ...{
                offset = document.cookie.indexOf(search)
                if(offset != -1)
                ...{
                        offset += search.length
                        end = document.cookie.indexOf(";", offset)
                        if(end == -1) end = document.cookie.length
                        return unescape(document.cookie.substring(offset, end))
                }
                else return "";
        }
}

//存储cookie
function setCookie(name, value, days)
...{
        if (days)
        ...{
                var date = new Date();
                date.setTime(date.getTime() + (days*24*60*60*1000));
                var expires = ";expires=" + date.toGMTString();
        }
        else var expires = "";
        document.cookie = name + "=" + value + expires + ";path=/;domain=" + document.location.hostname;
}

function eventFalse()
...{
        window.event.returnValue = false;
}

//document.oncontextmenu = eventFalse;
//document.onselectstart = eventFalse;
//-->


一、验证类
1、数字验证内
  1.1 整数
      /^(-|+)?d+$/.test(str)
  1.2 大于0的整数 (用于传来的ID的验证)
      /^d+$/.test(str)
  1.3 负整数的验证
      /^-d+$/.test(str)
2、时间类
  2.1 短时间,形如 (13:04:06)
      function isTime(str)
      {
        var a = str.match(/^(d{1,2})(:)?(d{1,2})2(d{1,2})$/);
        if (a == null) {alert('输入的参数不是时间格式'); return false;}
        if (a[1]>24 || a[3]>60 || a[4]>60)
        {
          alert("时间格式不对");
          return false
        }
        return true;
      }
  2.2 短日期,形如 (2003-12-05)
      function strDateTime(str)
      {
         var r = str.match(/^(d{1,4})(-|/)(d{1,2})2(d{1,2})$/);
         if(r==null)return false;
         var d= new Date(r[1], r[3]-1, r[4]);
         return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]);
      }
  2.3 长时间,形如 (2003-12-05 13:04:06)
      function strDateTime(str)
      {
        var reg = /^(d{1,4})(-|/)(d{1,2})2(d{1,2}) (d{1,2}):(d{1,2}):(d{1,2})$/;
        var r = str.match(reg);
        if(r==null)return false;
        var d= new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]);
        return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]&&d.getHours()==r[5]&&d.getMinutes()==r[6]&&d.getSeconds()==r[7]);
      }
  2.4 只有年和月。形如(2003-05,或者2003-5)
  2.5 只有小时和分钟,形如(12:03)
3、表单类
  3.1 所有的表单的值都不能为空
      <input οnblur="if(this.value.replace(/^s+|s+$/g,'')=='')alert('不能为空!')">
  3.2 多行文本框的值不能为空。
  3.3 多行文本框的值不能超过sMaxStrleng
  3.4 多行文本框的值不能少于sMixStrleng
  3.5 判断单选框是否选择。
  3.6 判断复选框是否选择.
  3.7 复选框的全选,多选,全不选,反选
  3.8 文件上传过程中判断文件类型
4、字符类
  4.1 判断字符全部由a-Z或者是A-Z的字字母组成
      <input οnblur="if(/[^a-zA-Z]/g.test(this.value))alert('有错')">
  4.2 判断字符由字母和数字组成。
      <input οnblur="if(/[^0-9a-zA-Z]/g.test(this.value))alert('有错')">
  4.3 判断字符由字母和数字,下划线,点号组成.且开头的只能是下划线和字母
      /^([a-zA-z_]{1})([w]*)$/g.test(str)
  4.4 字符串替换函数.Replace();
5、浏览器类
  5.1 判断浏览器的类型
      window.navigator.appName
  5.2 判断ie的版本
      window.navigator.appVersion
  5.3 判断客户端的分辨率
      window.screen.height;  window.screen.width;
 
6、结合类
  6.1 email的判断。
      function ismail(mail)
      {
        return(new RegExp(/^w+((-w+)|(.w+))*@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+)*.[A-Za-z0-9]+$/).test(mail));
      }
  6.2 手机号码的验证
  6.3 身份证的验证
      function isIdCardNo(num)
      {
        if (isNaN(num)) {alert("输入的不是数字!"); return false;}
        var len = num.length, re;
        if (len == 15)
          re = new RegExp(/^(d{6})()?(d{2})(d{2})(d{2})(d{3})$/);
        else if (len == 18)
          re = new RegExp(/^(d{6})()?(d{4})(d{2})(d{2})(d{3})(d)$/);
        else {alert("输入的数字位数不对!"); return false;}
        var a = num.match(re);
        if (a != null)
        {
          if (len==15)
          {
            var D = new Date("19"+a[3]+"/"+a[4]+"/"+a[5]);
            var B = D.getYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5];
          }
          else
          {
            var D = new Date(a[3]+"/"+a[4]+"/"+a[5]);
            var B = D.getFullYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5];
          }
          if (!B) {alert("输入的身份证号 "+ a[0] +" 里出生日期不对!"); return false;}
        }
        return true;
      }

3.7 复选框的全选,多选,全不选,反选
<form name=hrong>
<input type=checkbox name=All οnclick="checkAll('mm')">全选<br/>
<input type=checkbox name=mm οnclick="checkItem('All')"><br/>
<input type=checkbox name=mm οnclick="checkItem('All')"><br/>
<input type=checkbox name=mm οnclick="checkItem('All')"><br/>
<input type=checkbox name=mm οnclick="checkItem('All')"><br/>
<input type=checkbox name=mm οnclick="checkItem('All')"><br/><br/>


<input type=checkbox name=All2 οnclick="checkAll('mm2')">全选<br/>
<input type=checkbox name=mm2 οnclick="checkItem('All2')"><br/>
<input type=checkbox name=mm2 οnclick="checkItem('All2')"><br/>
<input type=checkbox name=mm2 οnclick="checkItem('All2')"><br/>
<input type=checkbox name=mm2 οnclick="checkItem('All2')"><br/>
<input type=checkbox name=mm2 οnclick="checkItem('All2')"><br/>

</form>

<SCRIPT LANGUAGE="JavaScript">
function checkAll(str)
{
  var a = document.getElementsByName(str);
  var n = a.length;
  for (var i=0; i<n; i++)
  a.checked = window.event.srcElement.checked;
}
function checkItem(str)
{
  var e = window.event.srcElement;
  var all = eval("document.hrong."+ str);
  if (e.checked)
  {
    var a = document.getElementsByName(e.name);
    all.checked = true;
    for (var i=0; i<a.length; i++)
    {
      if (!a.checked){ all.checked = false; break;}
    }
  }
  else all.checked = false;
}
</SCRIPT>

3.8 文件上传过程中判断文件类型
<input type=file οnchange="alert(this.value.match(/^(.*)(.)(.{1,8})$/)[3])">

画图:
<OBJECT
id=S
style="LEFT: 0px; WIDTH: 392px; TOP: 0px; HEIGHT: 240px"
height=240
width=392
classid="clsid:369303C2-D7AC-11D0-89D5-00A0C90833E6">
</OBJECT>
<SCRIPT>
S.DrawingSurface.ArcDegrees(0,0,0,30,50,60);
S.DrawingSurface.ArcRadians(30,0,0,30,50,60);
S.DrawingSurface.Line(10,10,100,100);
</SCRIPT>

写注册表:
<SCRIPT>
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.RegWrite ("HKCUSoftwareACMEFortuneTeller", 1, "REG_BINARY");
WshShell.RegWrite ("HKCUSoftwareACMEFortuneTellerMindReader", "Goocher!", "REG_SZ");
var bKey =    WshShell.RegRead ("HKCUSoftwareACMEFortuneTeller");
WScript.Echo (WshShell.RegRead ("HKCUSoftwareACMEFortuneTellerMindReader"));
WshShell.RegDelete ("HKCUSoftwareACMEFortuneTellerMindReader");
WshShell.RegDelete ("HKCUSoftwareACMEFortuneTeller");
WshShell.RegDelete ("HKCUSoftwareACME");
</SCRIPT>

TABLAE相关(客户端动态增加行列)
<HTML>
<SCRIPT LANGUAGE="JScript">
function numberCells() {
    var count=0;
    for (i=0; i < document.all.mytable.rows.length; i++) {
        for (j=0; j < document.all.mytable.rows(i).cells.length; j++) {
            document.all.mytable.rows(i).cells(j).innerText = count;
            count++;
        }
    }
}
</SCRIPT>
<BODY "numberCells()">
<TABLE id=mytable border=1>
<TR><TH> </TH><TH> </TH><TH> </TH><TH> </TH></TR>
<TR><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR>
<TR><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR>
</TABLE>
</BODY>
</HTML>

1.身份证严格验证:

<script>
var aCity={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:" 黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42: "湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54: "西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91: "国外"}
 
function cidInfo(sId){
 var iSum=0
 var info=""
 if(!/^d{17}(d|x)$/i.test(sId))return false;
 sId=sId.replace(/x$/i,"a");
 if(aCity[parseInt(sId.substr(0,2))]==null)return "Error:非法地区";
 sBirthday=sId.substr(6,4)+"-"+Number(sId.substr(10,2))+"-"+Number(sId.substr(12,2));
 var d=new Date(sBirthday.replace(/-/g,"/"))
 if(sBirthday!=(d.getFullYear()+"-"+ (d.getMonth()+1) + "-" + d.getDate()))return "Error:非法生日";
 for(var i = 17;i>=0;i --) iSum += (Math.pow(2,i) % 11) * parseInt(sId.charAt(17 - i),11)
 if(iSum%11!=1)return "Error:非法证号";
 return aCity[parseInt(sId.substr(0,2))]+","+sBirthday+","+(sId.substr(16,1)%2?"男":"女")
}

document.write(cidInfo("380524198002300016"),"<br/>");
document.write(cidInfo("340524198002300019"),"<br/>")
document.write(cidInfo("340524197711111111"),"<br/>")
document.write(cidInfo("34052419800101001x"),"<br/>");
</script>

2.验证IP地址
<SCRIPT LANGUAGE="JavaScript">
function isip(s){
 var check=function(v){try{return (v<=255 && v>=0)}catch(x){return false}};
 var re=s.split(".")
 return (re.length==4)?(check(re[0]) && check(re[1]) && check(re[2]) && check(re[3])):false
}

var s="202.197.78.129";
alert(isip(s))
</SCRIPT>

 

3.加sp1后还能用的无边框窗口!!
<HTML XMLNS:IE>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<IE:Download ID="include" STYLE="behavior:url(#default#download)" />
<title>Chromeless Window</title>

<SCRIPT LANGUAGE="JScript">
/*--- Special Thanks For andot ---*/

/*
 This following code are designed and writen by Windy_sk <seasonx@163.net>
 You can use it freely, but u must held all the copyright items!
*/

/*--- Thanks For andot Again ---*/

var CW_width = 400;
var CW_height = 300;
var CW_top = 100;
var CW_left = 100;
var CW_url = "/";
var New_CW = window.createPopup();
var CW_Body = New_CW.document.body;
var content = "";
var CSStext = "margin:1px;color:black; border:2px outset;border-style:expression(οnmοuseοut=οnmοuseup=function(){this.style.borderStyle='outset'}, οnmοusedοwn=function(){if(event.button!=2)this.style.borderStyle='inset'});background-color:buttonface;width:16px;height:14px;font-size:12px;line-height:11px;cursor:Default;";

//Build Window
include.startDownload(CW_url, function(source){content=source});

function insert_content(){
 var temp = "";
 CW_Body.style.overflow  = "hidden";
 CW_Body.style.backgroundColor = "white";
 CW_Body.style.border  =  "solid black 1px";
 content = content.replace(/<a ([^>]*)>/g,"<a οnclick='parent.open(this.href);return false' $1>");
 temp += "<table width=100% height=100% cellpadding=0 cellspacing=0 border=0>";
 temp += "<tr style=';font-size:12px;background:#0099CC;height:20;cursor:default' οndblclick="Max.innerText=Max.innerText=='1'?'2':'1';parent.if_max=!parent.if_max;parent.show_CW();" οnmοuseup='parent.drag_up(event)' οnmοusemοve='parent.drag_move(event)' οnmοusedοwn='parent.drag_down(event)' onselectstart='return false' οncοntextmenu='return false'>";
 temp += "<td style='color:#ffffff;padding-left:5px'>Chromeless Window For IE6 SP1</td>";
 temp += "<td style='color:#ffffff;padding-right:5px;' align=right>";
 temp += "<span id=Help  οnclick="alert('Chromeless Window For IE6 SP1  -  Ver 1.0 Code By Windy_sk Special Thanks For andot')" style=""+CSStext+"font-family:System;padding-right:2px;">?</span>";
 temp += "<span id=Min   οnclick='parent.New_CW.hide();parent.blur()' style=""+CSStext+"font-family:Webdings;" title='Minimum'>0</span>";
 temp += "<span id=Max   οnclick="this.innerText=this.innerText=='1'?'2':'1';parent.if_max=!parent.if_max;parent.show_CW();" style=""+CSStext+"font-family:Webdings;" title='Maximum'>1</span>";
 temp += "<span id=Close οnclick='parent.opener=null;parent.close()' style=""+CSStext+"font-family:System;padding-right:2px;" title='Close'>x</span>";
 temp += "</td></tr><tr><td colspan=2>";
 temp += "<div id=include style='overflow:scroll;overflow-x:hidden;overflow-y:auto; HEIGHT: 100%; width:"+CW_width+"'>";
 temp += content;
 temp += "</div>";
 temp += "</td></tr></table>";
 CW_Body.innerHTML = temp;
}

setTimeout("insert_content()",1000);

var if_max = true;
function show_CW(){
 window.moveTo(10000, 10000);
 if(if_max){
  New_CW.show(CW_top, CW_left, CW_width, CW_height);
  if(typeof(New_CW.document.all.include)!="undefined"){
   New_CW.document.all.include.style.width = CW_width;
   New_CW.document.all.Max.innerText = "1";
  }
 
 }else{
  New_CW.show(0, 0, screen.width, screen.height);
  New_CW.document.all.include.style.width = screen.width;
 }
}

window.onfocus  = show_CW;
window.onresize = show_CW;

// Move Window
var drag_x,drag_y,draging=false

function drag_move(e){
 if (draging){
  New_CW.show(e.screenX-drag_x, e.screenY-drag_y, CW_width, CW_height);
  return false;
 }
}

function drag_down(e){
 if(e.button==2)return;
 if(New_CW.document.body.offsetWidth==screen.width && New_CW.document.body.offsetHeight==screen.height)return;
 drag_x=e.clientX;
 drag_y=e.clientY;
 draging=true;
 e.srcElement.setCapture();
}

function drag_up(e){
 draging=false;
 e.srcElement.releaseCapture();
 if(New_CW.document.body.offsetWidth==screen.width && New_CW.document.body.offsetHeight==screen.height) return;
 CW_top  = e.screenX-drag_x;
 CW_left = e.screenY-drag_y;
}

</SCRIPT>
</HTML>

电话号码的验证

要求:
  (1)电话号码由数字、"("、")"和"-"构成
  (2)电话号码为3到8位
  (3)如果电话号码中包含有区号,那么区号为三位或四位
  (4)区号用"("、")"或"-"和其他部分隔开
  (5)移动电话号码为11或12位,如果为12位,那么第一位为0
  (6)11位移动电话号码的第一位和第二位为"13"
  (7)12位移动电话号码的第二位和第三位为"13"
  根据这几条规则,可以与出以下正则表达式:
  (^[0-9]{3,4}-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^([0-9]{3,4})[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)


<script language="javascript">
function PhoneCheck(s) {
var str=s;
var reg=/(^[0-9]{3,4}-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^([0-9]{3,4})[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/
alert(reg.test(str));
}
</script>
<input type=text name="iphone">
<input type=button οnclick="PhoneCheck(document.all.iphone.value)" value="Check">

具有在输入非数字字符不回显的效果,即对非数字字符的输入不作反应。
function numbersonly(field,event){
 var key,keychar;
 if(window.event){
  key = window.event.keyCode;
 }
 else if (event){
  key = event.which;
 }
 else{
  return true
 }
 keychar = String.fromCharCode(key);
 if((key == null)||(key == 0)||(key == 8)||(key == 9)||(key == 13)||(key == 27)){
  return true;
 }
 else if(("0123456789.").indexOf(keychar)>-1){
  window.status = "";
  return true;
 }
 else {
  window.status = "Field excepts numbers only";
  return false;
 }
}

验证ip

str=document.RegExpDemo.txtIP.value;
if(/^(d{1,3}).(d{1,3}).(d{1,3}).(d{1,3})$/.test(str)==false)
{
 window.alert('错误的IP地址格式');
 document.RegExpDemo.txtIP.select();
 document.RegExpDemo.txtIP.focus();
 return;
}
if(RegExp.$1<1 || RegExp.$1>254||RegExp.$2<0||RegExp.$2>254||RegExp.$3<0||RegExp.$3>254||RegExp.$4<1||RegExp.$4>254)
{
 window.alert('错误的IP地址');
 document.RegExpDemo.txtIP.select();
 document.RegExpDemo.txtIP.focus();
 return;
}
//剔除 如  010.020.020.03 前面 的0
var str=str.replace(/0(d)/g,"$1");
str=str.replace(/0(d)/g,"$1");
window.alert(str);

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AI程序代码艺术家/article/detail/60578
推荐阅读
相关标签
  

闽ICP备14008679号