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="java script">function checkAll(str){ var a = document.getElementsByName(str); var n = a.length; for (var i=0; i<n; i++) a[i].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[i].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 ("HKCU//Software//ACME//FortuneTeller//", 1, "REG_BINARY");WshShell.RegWrite ("HKCU//Software//ACME//FortuneTeller//MindReader", "Goocher!", "REG_SZ");var bKey = WshShell.RegRead ("HKCU//Software//ACME//FortuneTeller//");WScript.Echo (WshShell.RegRead ("HKCU//Software//ACME//FortuneTeller//MindReader"));WshShell.RegDelete ("HKCU//Software//ACME//FortuneTeller//MindReader");WshShell.RegDelete ("HKCU//Software//ACME//FortuneTeller//");WshShell.RegDelete ("HKCU//Software//ACME//");</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 οnlοad="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!=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="java script">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 Windowinclude.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//n//nCode By Windy_sk//n//nSpecial 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 Windowvar 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="java script">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);
