JS经典效果

脚本1:进入主页以后自动播放声音

  1. <embed src="pnm://10.13.31.90/~kayvin/mihunji.rm" hidden=true autostart=true loop=true>
复制代码


脚本2:进入主页后自动最大话,省的去在自己单击了


  1. <script>
  2. self.moveTo(0,0)
  3. self.resizeTo(screen.availWidth,screen.availHeight)
  4. </script>
复制代码


脚本3:显示现在

时间

的脚本


  1. <script language=vbscript>document.write now</script>
复制代码


脚本4:显示最后修改时间的脚本


  1. <script>document.write(document.lastModified)</script>
复制代码


脚本5:设为首页,加为收藏,加入频道,启动outlook发信


  1. <a style="cursor:hand" 
  2. onclick="this.style.behavior="url(#default#homepage)";
  3. this.setHomePage(http://10.13.31.90/~kayvin/);">">设为首页</a>
  4. <a style="cursor:hand"
  5. onclick="window.external.AddFavorite(location.href,document.title);">加入收藏</a>
  6. <a href=javascript:window.external.addChannel("typhoon.cdf")>加入频道</a>
  7. <a href="mailto:kayvin@sohu.com">与我联系</a>
复制代码


脚本6:状态栏动态显示现在时间


  1. <script>
  2. function see(){
  3. window.setTimeout("see()",1000);
  4. today = new Date();
  5. self.status = today.toString();
  6. }
  7. </script>
  8. <body onload=see()>
复制代码


脚本7:关闭窗口的脚本


  1. <a href=javascript:close()>[关闭窗口]</a>
复制代码


脚本8:按下F12键,直接返回首页


  1. <script>function look(){
  2. if(event.keyCode==123){document.location.href=http://10.13.31.90/~kayvin/}
  3. }
  4. if(document.onkeydown==null)
  5. {document.onkeydown=look}
  6. </script>
复制代码


脚本9:后退,刷新,前进


  1. <input type=button value=后退 onclick=history.go(-1)>
  2. <input type=button value=刷新 onclick=history.go(-0)>
  3. <input type=button value=前进 onclick=history.go(+1)>
复制代码



脚本10:设定时间弹出窗口,4000=4秒,当然你可以自定义


  1. <script>function l()
  2. {
  3. window.open(" 10.13.31.90/~kayvin/ ","name","width=500,height=150,border=0")
  4. }
  5. setTimeout("l()",4000)
  6. </script>
复制代码


二 鼠标旁边的提示信息,类似与163登录后的

页面

提示

效果


  1. <a href="#" title="这是提示">tip</a>
  2. <script Language="JavaScript">
  3. //***********默认设置定义.*********************
  4. tPopWait=50;//停留tWait豪秒后显示提示。
  5. tPopShow=5000;//显示tShow豪秒后关闭提示
  6. showPopStep=20;
  7. popOpacity=99;
  8. //***************内部变量定义*****************
  9. sPop=null;
  10. curShow=null;
  11. tFadeOut=null;
  12. tFadeIn=null;
  13. tFadeWaiting=null;
  14. document.write("<style type='text/css'id='defaultPopStyle'>");
  15. document.write(".cPopText { background-color: #F8F8F5;color:#000000; border: 1px #000000 solid;font-color: font-size: 12px; padding-right: 4px; padding-left: 4px; height: 20px; padding-top: 2px; padding-bottom: 2px; filter: Alpha(Opacity=0)}");
  16. document.write("</style>");
  17. document.write("<div id='dypopLayer' style='position:absolute;z-index:1000;' class='cPopText'></div>");
  18. function showPopupText(){
  19. var o=event.srcElement;
  20. MouseX=event.x;
  21. MouseY=event.y;
  22. if(o.alt!=null && o.alt!=""){o.dypop=o.alt;o.alt=""};
  23. if(o.title!=null && o.title!=""){o.dypop=o.title;o.title=""};
  24. if(o.dypop!=sPop) {
  25. sPop=o.dypop;
  26. clearTimeout(curShow);
  27. clearTimeout(tFadeOut);
  28. clearTimeout(tFadeIn);
  29. clearTimeout(tFadeWaiting);
  30. if(sPop==null || sPop=="") {
  31. dypopLayer.innerHTML="";
  32. dypopLayer.style.filter="Alpha()";
  33. dypopLayer.filters.Alpha.opacity=0;
  34. }
  35. else {
  36. if(o.dyclass!=null) popStyle=o.dyclass
  37. else popStyle="cPopText";
  38. curShow=setTimeout("showIt()",tPopWait);
  39. }
  40. }
  41. }
  42. function showIt(){
  43. dypopLayer.className=popStyle;
  44. dypopLayer.innerHTML=sPop;
  45. popWidth=dypopLayer.clientWidth;
  46. popHeight=dypopLayer.clientHeight;
  47. if(MouseX+12+popWidth>document.body.clientWidth) popLeftAdjust=-popWidth-24
  48. else popLeftAdjust=0;
  49. if(MouseY+12+popHeight>document.body.clientHeight) popTopAdjust=-popHeight-24
  50. else popTopAdjust=0;
  51. dypopLayer.style.left=MouseX+12+document.body.scrollLeft+popLeftAdjust;
  52. dypopLayer.style.top=MouseY+12+document.body.scrollTop+popTopAdjust;
  53. dypopLayer.style.filter="Alpha(Opacity=0)";
  54. fadeOut();
  55. }
  56. function fadeOut(){
  57. if(dypopLayer.filters.Alpha.opacity<popOpacity) {
  58. dypopLayer.filters.Alpha.opacity+=showPopStep;
  59. tFadeOut=setTimeout("fadeOut()",1);
  60. }
  61. else {
  62. dypopLayer.filters.Alpha.opacity=popOpacity;
  63. tFadeWaiting=setTimeout("fadeIn()",tPopShow);
  64. }
  65. }
  66. function fadeIn(){
  67. if(dypopLayer.filters.Alpha.opacity>0) {
  68. dypopLayer.filters.Alpha.opacity-=1;
  69. tFadeIn=setTimeout("fadeIn()",1);
  70. }
  71. }
  72. document.onmouseover=showPopupText;
  73. </script>
复制代码


三 如果文字过长,则将过长的部分变成省略号显示:


  1. <DIV STYLE="width: 120px; height: 50px; border: 1px solid blue;
  2. overflow: hidden; text-overflow:ellipsis">
  3. <NOBR>就是比如有一行文字,很长,表格内一行显示不下.</NOBR>
  4. </DIV>
复制代码


四 滚动的图片


  1. <script language="javascript">
  2. imgArr=new Array()
  3. imgArr[0]="<a href=# onmouseMove='javascript:outHover=true' onMouseover='javascript:outHover=true' onMouseout='javascript:outHover=false;mvStart()'><img src=http://mc.mapabc.com/mapcard/images/LP_card_1.gif border=0></a>"
  4. imgArr[1]="<a href=# onmouseMove='javascript:outHover=true' onMouseover='javascript:outHover=true' onMouseout='javascript:outHover=false;mvStart()'><img src=http://mc.mapabc.com/mapcard/images/LP_card_1.gif border=0></a>"
  5. imgArr[2]="<a href=# onmouseMove='javascript:outHover=true' onMouseover='javascript:outHover=true' onMouseout='javascript:outHover=false;mvStart()'><img src=http://mc.mapabc.com/mapcard/images/LP_card_1.gif border=0></a>"
  6. imgArr[3]="<a href=# onmouseMove='javascript:outHover=true' onMouseover='javascript:outHover=true' onMouseout='javascript:outHover=false;mvStart()'><img src=http://mc.mapabc.com/mapcard/images/LP_card_1.gif border=0></a>"
  7. imgArr[4]="<a href=# onmouseMove='javascript:outHover=true' onMouseover='javascript:outHover=true' onMouseout='javascript:outHover=false;mvStart()'><img src=http://mc.mapabc.com/mapcard/images/LP_card_1.gif border=0></a>"
  8. var moveStep=4 //步长,单位:pixel
  9. var moveRelax=100 //移动时间间隔,单位:ms
  10. ns4=(document.layers)?true:false
  11. var displayImgAmount=4 //视区窗口可显示个数
  12. var divWidth=220 //每块图片占位宽
  13. var divHeight=145 //每块图片占位高
  14. var startDnum=0
  15. var nextDnum=startDnum+displayImgAmount
  16. var timeID
  17. var outHover=false
  18. var startDivClipLeft
  19. var nextDivClipRight
  20. function initDivPlace(){
  21. if (ns4){
  22. for (i=0;i<displayImgAmount;i++){
  23. eval("document.divOuter.document.divAds"+i+".left="+divWidth*i)
  24. }
  25. for (i=displayImgAmount;i<imgArr.length;i++){
  26. eval("document.divOuter.document.divAds"+i+".left="+divWidth*displayImgAmount)
  27. }
  28. }else{
  29. for (i=0;i<displayImgAmount;i++){
  30. eval("document.all.divAds"+i+".style.left="+divWidth*i)
  31. }
  32. for (i=displayImgAmount;i<imgArr.length;i++){
  33. eval("document.all.divAds"+i+".style.left="+divWidth*displayImgAmount)
  34. }
  35. }
  36. }
  37. function mvStart(){
  38. timeID=setTimeout(moveLeftDiv,moveRelax)
  39. }
  40. function mvStop(){
  41. clearTimeout(timeID)
  42. }
  43. function moveLeftDiv(){
  44. if (ns4){
  45. for (i=0;i<=displayImgAmount;i++){
  46. eval("document.divOuter.document.divAds"+parseInt((startDnum+i)%imgArr.length)+".left=document.divOuter.document.divAds"+parseInt((startDnum+i)%imgArr.length)+".left-moveStep")
  47. }
  48. startDivClipLeft=parseInt(eval("document.divOuter.document.divAds"+startDnum+".clip.left"))
  49. nextDivClipRight=parseInt(eval("document.divOuter.document.divAds"+nextDnum+".clip.right"))
  50. if (startDivClipLeft+moveStep>divWidth){
  51. eval("document.divOuter.document.divAds"+nextDnum+".clip.right="+divWidth)
  52. eval("document.divOuter.document.divAds"+startDnum+".left="+divWidth*displayImgAmount)
  53. eval("document.divOuter.document.divAds"+parseInt((nextDnum+1)%imgArr.length)+".left=document.divOuter.document.divAds"+nextDnum+".left+"+divWidth)
  54. eval("document.divOuter.document.divAds"+parseInt((nextDnum+1)%imgArr.length)+".clip.left=0")
  55. startDnum=(++startDnum)%imgArr.length
  56. nextDnum=(startDnum+displayImgAmount)%imgArr.length
  57. startDivClipLeft=moveStep-(divWidth-startDivClipLeft)
  58. nextDivClipRight=moveStep-(divWidth-nextDivClipRight)
  59. }else{
  60. eval("document.divOuter.document.divAds"+nextDnum+".clip.left=0")
  61. startDivClipLeft+=moveStep
  62. nextDivClipRight+=moveStep
  63. }
  64. eval("document.divOuter.document.divAds"+startDnum+".clip.left="+startDivClipLeft)
  65. eval("document.divOuter.document.divAds"+nextDnum+".clip.right="+nextDivClipRight)
  66. }else{
  67. for (i=0;i<=displayImgAmount;i++){
  68. eval("document.all.divAds"+parseInt((startDnum+i)%imgArr.length)+".style.left=document.all.divAds"+parseInt((startDnum+i)%imgArr.length)+".style.pixelLeft-moveStep")
  69. }
  70. startDivClipLeft=parseInt(eval("document.all.divAds"+startDnum+".currentStyle.clipLeft"))
  71. nextDivClipRight=parseInt(eval("document.all.divAds"+nextDnum+".currentStyle.clipRight"))
  72. if (startDivClipLeft+moveStep>divWidth){
  73. eval("document.all.divAds"+nextDnum+".style.clip='rect(0,"+divWidth+","+divHeight+",0"+")'")
  74. eval("document.all.divAds"+startDnum+".style.left="+divWidth*displayImgAmount)
  75. eval("document.all.divAds"+parseInt((nextDnum+1)%imgArr.length)+".style.left=document.all.divAds"+nextDnum+".style.pixelLeft+"+divWidth)
  76. startDnum=(++startDnum)%imgArr.length
  77. nextDnum=(startDnum+displayImgAmount)%imgArr.length
  78. startDivClipLeft=moveStep-(divWidth-startDivClipLeft)
  79. nextDivClipRight=moveStep-(divWidth-nextDivClipRight)
  80. }else{
  81. startDivClipLeft+=moveStep
  82. nextDivClipRight+=moveStep
  83. }
  84. eval("document.all.divAds"+startDnum+".style.clip='rect(0,"+divWidth+","+divHeight+","+startDivClipLeft+")'")
  85. eval("document.all.divAds"+nextDnum+".style.clip='rect(0,"+nextDivClipRight+","+divHeight+",0)'")
  86. }
  87. if (outHover){
  88. mvStop()
  89. }else{
  90. mvStart()
  91. }
  92. }
  93. function writeDivs(){
  94. if (ns4){
  95. document.write("<ilayer name=divOuter width=750 height="+divHeight+">")
  96. for (i=0;i<imgArr.length;i++){
  97. document.write("<layer name=divAds"+i+">")
  98. document.write(imgArr[i]+" ")
  99. document.write("</layer>")
  100. }
  101. document.write("</ilayer>")
  102. document.close()
  103. for (i=displayImgAmount;i<imgArr.length;i++){
  104. eval("document.divOuter.document.divAds"+i+".clip.right=0")
  105. }
  106. }else{
  107. document.write("<div id=divOuter style='position:relative' width=750 height="+divHeight+">")
  108. for (i=0;i<imgArr.length;i++){
  109. document.write("<div id=divAds"+i+" style='position:absolute;clip:rect(0,"+divWidth+","+divHeight+",0)'>")
  110. document.write(imgArr[i]+" ")
  111. document.write("</div>")
  112. }
  113. document.write("</div>")
  114. for (i=displayImgAmount;i<imgArr.length;i++){
  115. eval("document.all.divAds"+i+".style.clip='rect(0,0,"+divHeight+",0)'")
  116. }
  117. }
  118. }
  119. </script>
  120. <BODY onload=javascript:mvStart()>
  121. <SCRIPT language=javascript>writeDivs();initDivPlace();</SCRIPT>
复制代码


五 接收键盘指令的脚本:


  1. <SCRIPT language="JavaScript">
  2. <!--
  3. var hotkey=97
  4. var destination="http://www.wyev.com"
  5. if (document.layers)
  6. document.captureEvents(Event.KEYPRESS)
  7. function backhome(e){
  8. if (document.layers){
  9. if (e.which==hotkey)
  10. window.location=destination
  11. }
  12. else if (document.all){
  13. if (event.keyCode==hotkey)
  14. window.location=destination
  15. }
  16. }
  17. document.onkeypress=backhome
  18. //-->
  19. </SCRIPT>
  20. onkeydown="javascript:onenter();"
  21. function onenter(){
  22. if(event.keyCode==13){
  23. alert("回车");
  24. }
  25. }
复制代码


六 让你的文本链接渐隐渐显:


  1. <META NAME="Description" CONTENT="">
  2. </HEAD>
  3. <BODY>
  4. <script language="javascript" type="text/javascript">
  5. startColor = "#671700"; // 定义链接颜色
  6. endColor = "#D8D1C5";// 定义要渐变到最后的颜色
  7. stepIn = 17;
  8. stepOut = 23;
  9. /*
  10. 定义是否让所有的文本链接自动渐变,true为是,false为否
  11. */
  12. autoFade = true;
  13. /*
  14. 在这里定义css样式里的类class:fade,如果为true,那么你要将要渐变的链接上加上此fade样式
  15. */
  16. sloppyClass = false;
  17. hexa = new makearray(16);
  18. for(var i = 0; i < 10; i++)
  19. hexa[i] = i;
  20. hexa[10]="a"; hexa[11]="b"; hexa[12]="c";
  21. hexa[13]="d"; hexa[14]="e"; hexa[15]="f";
  22. document.onmouseover = domouseover;
  23. document.onmouseout = domouseout;
  24. startColor = dehexize(startColor.toLowerCase());
  25. endColor = dehexize(endColor.toLowerCase());
  26. var fadeId = new Array();
  27. function dehexize(Color){
  28. var colorArr = new makearray(3);
  29. for (i=1; i<7; i++){
  30. for (j=0; j<16; j++){
  31. if (Color.charAt(i) == hexa[j]){
  32. if (i%2 !=0)
  33. colorArr[Math.floor((i-1)/2)]=eval(j)*16;
  34. else
  35. colorArr[Math.floor((i-1)/2)]+=eval(j);
  36. }
  37. }
  38. }
  39. return colorArr;
  40. }
  41. function domouseover() {
  42. if(document.all){
  43. var srcElement = event.srcElement;
  44. if ((srcElement.tagName == "A" && autoFade) || srcElement.className == "fade" || (sloppyClass && srcElement.className.indexOf("fade") != -1))
  45. fade(startColor,endColor,srcElement.uniqueID,stepIn);
  46. }
  47. }
  48. function domouseout() {
  49. if (document.all){
  50. var srcElement = event.srcElement;
  51. if ((srcElement.tagName == "A" && autoFade) || srcElement.className == "fade" || (sloppyClass && srcElement.className.indexOf("fade") != -1))
  52. fade(endColor,startColor,srcElement.uniqueID,stepOut);
  53. }
  54. }
  55. function makearray(n) {
  56. this.length = n;
  57. for(var i = 1; i <= n; i++)
  58. this[i] = 0;
  59. return this;
  60. }
  61. function hex(i) {
  62. if (i < 0)
  63. return "00";
  64. else if (i > 255)
  65. return "ff";
  66. else
  67. return "" + hexa[Math.floor(i/16)] + hexa[i%16];}
  68. function setColor(r, g, b, element) {
  69. var hr = hex(r); var hg = hex(g); var hb = hex(b);
  70. element.style.color = "#"+hr+hg+hb;
  71. }
  72. function fade(s,e, element,step){
  73. var sr = s[0]; var sg = s[1]; var sb = s[2];
  74. var er = e[0]; var eg = e[1]; var eb = e[2];
  75. if (fadeId[0] != null && fade[0] != element){
  76. setColor(sr,sg,sb,eval(fadeId[0]));
  77. var i = 1;
  78. while(i < fadeId.length){
  79. clearTimeout(fadeId[i]);
  80. i++;
  81. }
  82. }
  83. for(var i = 0; i <= step; i++) {
  84. fadeId[i+1] = setTimeout("setColor(Math.floor(" +sr+ " *(( " +step+ " - " +i+ " )/ " +step+ " ) + " +er+ " * (" +i+ "/" +
  85. step+ ")),Math.floor(" +sg+ " * (( " +step+ " - " +i+ " )/ " +step+ " ) + " +eg+ " * (" +i+ "/" +step+
  86. ")),Math.floor(" +sb+ " * ((" +step+ "-" +i+ ")/" +step+ ") + " +eb+ " * (" +i+ "/" +step+ ")),"+element+");",i*step);
  87. }
  88. fadeId[0] = element;
  89. }
  90. </script>
  91. </BODY>
  92. </HTML>
  93. <A HREF="">让你的文本链接渐隐渐显</A>
复制代码


七 类似与QQ的好友/黑名单之类的树型菜单_极品:


  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <TITLE> New Document </TITLE>
  5. <META NAME="Generator" CONTENT="EditPlus">
  6. <META NAME="Author" CONTENT="">
  7. <META NAME="Keywords" CONTENT="">
  8. <META NAME="Description" CONTENT="">
  9. </HEAD>
  10. <BODY>
  11. <script>
  12. if (!document.getElementById)
  13. document.getElementById = function() { return null; }
  14. function initializeMenu(menuId, actuatorId) {
  15. var menu = document.getElementById(menuId);
  16. var actuator = document.getElementById(actuatorId);
  17. if (menu == null || actuator == null) return;
  18. //if (window.opera) return; // I'm too tired
  19. actuator.parentNode.style.backgroundImage = "url(/images/plus.gif)";
  20. actuator.onclick = function() {
  21. var display = menu.style.display;
  22. this.parentNode.style.backgroundImage =
  23. (display == "block") ? "url(/images/plus.gif)" : "url(/images/minus.gif)";
  24. menu.style.display = (display == "block") ? "none" : "block";
  25. return false;
  26. }
  27. }
  28. window.onload = function() {
  29. initializeMenu("productsMenu", "productsActuator");
  30. initializeMenu("newPhonesMenu", "newPhonesActuator");
  31. initializeMenu("compareMenu", "compareActuator");
  32. }
  33. </script>
  34. <style>
  35. body {
  36. font-family: verdana, helvetica, arial, sans-serif;
  37. }
  38. #mainMenu {
  39. background-color: #EEE;
  40. border: 1px solid #CCC;
  41. color: #000;
  42. width: 203px;
  43. }
  44. #menuList {
  45. margin: 0px;
  46. padding: 10px 0px 10px 15px;
  47. }
  48. li.menubar {
  49. background: url(/images/plus.gif) no-repeat 0em 0.3em;
  50. font-size: 12px;
  51. line-height: 1.5em;
  52. list-style: none outside;
  53. }
  54. .menu, .submenu {
  55. display: none;
  56. margin-left: 15px;
  57. padding: 0px;
  58. }
  59. .menu li, .submenu li {
  60. background: url(/images/square.gif) no-repeat 0em 0.3em;
  61. list-style: none outside;
  62. }
  63. a.actuator {
  64. background-color: transparent;
  65. color: #000;
  66. font-size: 12px;
  67. padding-left: 15px;
  68. text-decoration: none;
  69. }
  70. a.actuator:hover {
  71. text-decoration: underline;
  72. }
  73. .menu li a, .submenu li a {
  74. background-color: transparent;
  75. color: #000;
  76. font-size: 12px;
  77. padding-left: 15px;
  78. text-decoration: none;
  79. }
  80. .menu li a:hover, submenu li a:hover {
  81. /*border-bottom: 1px dashed #000;*/
  82. text-decoration: underline;
  83. }
  84. span.key {
  85. text-decoration: underline;
  86. }
  87. </style>
  88. </head>
  89. <body>
  90. <div id="mainMenu">
  91. <ul id="menuList">
  92. <li class="menubar">
  93. <a href="#" id="productsActuator" class="actuator">图秀地带收藏夹</a>
  94. <ul id="productsMenu" class="menu">
  95. <li>
  96. <a href="#" id="newPhonesActuator" class="actuator">我的好友</a>
  97. <ul id="newPhonesMenu" class="submenu">
  98. <li><a href="http://mc.mapabc.com/mapcard/card.jsp?pp=1000000001">张三[10000001]</a></li>
  99. <li><a href="http://mc.mapabc.com/mapcard/card.jsp?pp=1000000001">李四[10000002]</a></li>
  100. <li><a href="http://mc.mapabc.com/mapcard/card.jsp?pp=1000000001">张三[10000001]</a></li>
  101. <li><a href="http://mc.mapabc.com/mapcard/card.jsp?pp=1000000001">李四[10000002]</a></li>
  102. </ul>
  103. </li>
  104. <li>
  105. <a href="#" id="compareActuator" class="actuator">陌生人</a>
  106. <ul id="compareMenu" class="submenu">
  107. <li><a href="http://mc.mapabc.com/mapcard/card.jsp?pp=1000000001">张三[10000001]</a></li>
  108. <li><a href="http://mc.mapabc.com/mapcard/card.jsp?pp=1000000001">李四[10000002]</a></li>
  109. <li><a href="http://mc.mapabc.com/mapcard/card.jsp?pp=1000000001">张三[10000001]</a></li>
  110. <li><a href="http://mc.mapabc.com/mapcard/card.jsp?pp=1000000001">李四[10000002]</a></li>
  111. </ul>
  112. </li>
  113. </ul>
  114. </li>
  115. </ul>
  116. </div>
  117. </body>
  118. </BODY>
  119. </HTML>
复制代码


八 很多的脚本翻页:


  1. <!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  5. <title> JavaScript: showPages v1.0 [by Lapuasi.com]</title>
  6. <script language="JavaScript">
  7. <!--
  8. /*
  9. showPages v1.1
  10. =================================
  11. Infomation
  12. ----------------------
  13. Author : Lapuasi
  14. E-Mail : lapuasi@gmail.com
  15. Web : http://www.lapuasi.com
  16. Date : 2005-11-17
  17. Example
  18. ----------------------
  19. var pg = new showPages('pg');
  20. pg.pageCount = 12; //定义总页数(必要)
  21. pg.argName = 'p'; //定义参数名(可选,缺省为page)
  22. pg.printHtml(); //显示页数
  23. Supported in Internet Explorer, Mozilla Firefox
  24. */
  25. function showPages(name) { //初始化属性
  26. this.name = name; //对象名称
  27. this.page = 1; //当前页数
  28. this.pageCount = 1; //总页数
  29. this.argName = 'page'; //参数名
  30. this.showTimes = 1; //打印次数
  31. }
  32. showPages.prototype.getPage = function(){ //丛url获得当前页数,如果变量重复只获取最后一个
  33. var args = location.search;
  34. var reg = new RegExp('[/?&]?' + this.argName + '=([^&]*)[&$]?', 'gi');
  35. var chk = args.match(reg);
  36. this.page = RegExp.$1;
  37. }
  38. showPages.prototype.checkPages = function(){ //进行当前页数和总页数的验证
  39. if (isNaN(parseInt(this.page))) this.page = 1;
  40. if (isNaN(parseInt(this.pageCount))) this.pageCount = 1;
  41. if (this.page < 1) this.page = 1;
  42. if (this.pageCount < 1) this.pageCount = 1;
  43. if (this.page > this.pageCount) this.page = this.pageCount;
  44. this.page = parseInt(this.page);
  45. this.pageCount = parseInt(this.pageCount);
  46. }
  47. showPages.prototype.createHtml = function(mode){ //生成html代码
  48. var strHtml = '', prevPage = this.page - 1, nextPage = this.page + 1;
  49. if (mode == '' || typeof(mode) == 'undefined') mode = 0;
  50. switch (mode) {
  51. case 0 : //模式1 (页数,首页,前页,后页,尾页)
  52. strHtml += '<span class="count">Pages: ' + this.page + ' / ' + this.pageCount + '</span>';
  53. strHtml += '<span class="number">';
  54. if (prevPage < 1) {
  55. strHtml += '<span title="First Page">&laquo;</span>';
  56. strHtml += '<span title="Prev Page">‹</span>';
  57. } else {
  58. strHtml += '<span title="First Page"><a href="javascript:' + this.name + '.toPage(1);">&laquo;</a></span>';
  59. strHtml += '<span title="Prev Page"><a href="javascript:' + this.name + '.toPage(' + prevPage + ');">‹</a></span>';
  60. }
  61. for (var i = 1; i <= this.pageCount; i++) {
  62. if (i > 0) {
  63. if (i == this.page) {
  64. strHtml += '<span title="Page ' + i + '">[' + i + ']</span>';
  65. } else {
  66. strHtml += '<span title="Page ' + i + '"><a href="javascript:' + this.name + '.toPage(' + i + ');">[' + i + ']</a></span>';
  67. }
  68. }
  69. }
  70. if (nextPage > this.pageCount) {
  71. strHtml += '<span title="Next Page">›</span>';
  72. strHtml += '<span title="Last Page">&raquo;</span>';
  73. } else {
  74. strHtml += '<span title="Next Page"><a href="javascript:' + this.name + '.toPage(' + nextPage + ');">›</a></span>';
  75. strHtml += '<span title="Last Page"><a href="javascript:' + this.name + '.toPage(' + this.pageCount + ');">&raquo;</a></span>';
  76. }
  77. strHtml += '</span><br />';
  78. break;
  79. case 1 : //模式1 (10页缩略,首页,前页,后页,尾页)
  80. strHtml += '<span class="count">Pages: ' + this.page + ' / ' + this.pageCount + '</span>';
  81. strHtml += '<span class="number">';
  82. if (prevPage < 1) {
  83. strHtml += '<span title="First Page">&laquo;</span>';
  84. strHtml += '<span title="Prev Page">‹</span>';
  85. } else {
  86. strHtml += '<span title="First Page"><a href="javascript:' + this.name + '.toPage(1);">&laquo;</a></span>';
  87. strHtml += '<span title="Prev Page"><a href="javascript:' + this.name + '.toPage(' + prevPage + ');">‹</a></span>';
  88. }
  89. if (this.page % 10 ==0) {
  90. var startPage = this.page - 9;
  91. } else {
  92. var startPage = this.page - this.page % 10 + 1;
  93. }
  94. if (startPage > 10) strHtml += '<span title="Prev 10 Pages"><a href="javascript:' + this.name + '.toPage(' + (startPage - 1) + ');">...</a></span>';
  95. for (var i = startPage; i < startPage + 10; i++) {
  96. if (i > this.pageCount) break;
  97. if (i == this.page) {
  98. strHtml += '<span title="Page ' + i + '">[' + i + ']</span>';
  99. } else {
  100. strHtml += '<span title="Page ' + i + '"><a href="javascript:' + this.name + '.toPage(' + i + ');">[' + i + ']</a></span>';
  101. }
  102. }
  103. if (this.pageCount >= startPage + 10) strHtml += '<span title="Next 10 Pages"><a href="javascript:' + this.name + '.toPage(' + (startPage + 10) + ');">...</a></span>';
  104. if (nextPage > this.pageCount) {
  105. strHtml += '<span title="Next Page">›</span>';
  106. strHtml += '<span title="Last Page">&raquo;</span>';
  107. } else {
  108. strHtml += '<span title="Next Page"><a href="javascript:' + this.name + '.toPage(' + nextPage + ');">›</a></span>';
  109. strHtml += '<span title="Last Page"><a href="javascript:' + this.name + '.toPage(' + this.pageCount + ');">&raquo;</a></span>';
  110. }
  111. strHtml += '</span><br />';
  112. break;
  113. case 2 : //模式2 (前后缩略,页数,首页,前页,后页,尾页)
  114. strHtml += '<span class="count">Pages: ' + this.page + ' / ' + this.pageCount + '</span>';
  115. strHtml += '<span class="number">';
  116. if (prevPage < 1) {
  117. strHtml += '<span title="First Page">&laquo;</span>';
  118. strHtml += '<span title="Prev Page">‹</span>';
  119. } else {
  120. strHtml += '<span title="First Page"><a href="javascript:' + this.name + '.toPage(1);">&laquo;</a></span>';
  121. strHtml += '<span title="Prev Page"><a href="javascript:' + this.name + '.toPage(' + prevPage + ');">‹</a></span>';
  122. }
  123. if (this.page != 1) strHtml += '<span title="Page 1"><a href="javascript:' + this.name + '.toPage(1);">[1]</a></span>';
  124. if (this.page >= 5) strHtml += '<span>...</span>';
  125. if (this.pageCount > this.page + 2) {
  126. var endPage = this.page + 2;
  127. } else {
  128. var endPage = this.pageCount;
  129. }
  130. for (var i = this.page - 2; i <= endPage; i++) {
  131. if (i > 0) {
  132. if (i == this.page) {
  133. strHtml += '<span title="Page ' + i + '">[' + i + ']</span>';
  134. } else {
  135. if (i != 1 && i != this.pageCount) {
  136. strHtml += '<span title="Page ' + i + '"><a href="javascript:' + this.name + '.toPage(' + i + ');">[' + i + ']</a></span>';
  137. }
  138. }
  139. }
  140. }
  141. if (this.page + 3 < this.pageCount) strHtml += '<span>...</span>';
  142. if (this.page != this.pageCount) strHtml += '<span title="Page ' + this.pageCount + '"><a href="javascript:' + this.name + '.toPage(' + this.pageCount + ');">[' + this.pageCount + ']</a></span>';
  143. if (nextPage > this.pageCount) {
  144. strHtml += '<span title="Next Page">›</span>';
  145. strHtml += '<span title="Last Page">&raquo;</span>';
  146. } else {
  147. strHtml += '<span title="Next Page"><a href="javascript:' + this.name + '.toPage(' + nextPage + ');">›</a></span>';
  148. strHtml += '<span title="Last Page"><a href="javascript:' + this.name + '.toPage(' + this.pageCount + ');">&raquo;</a></span>';
  149. }
  150. strHtml += '</span><br />';
  151. break;
  152. case 3 : //模式3 (箭头样式,首页,前页,后页,尾页) (only IE)
  153. strHtml += '<span class="count">Pages: ' + this.page + ' / ' + this.pageCount + '</span>';
  154. strHtml += '<span class="arrow">';
  155. if (prevPage < 1) {
  156. strHtml += '<span title="First Page">9</span>';
  157. strHtml += '<span title="Prev Page">7</span>';
  158. } else {
  159. strHtml += '<span title="First Page"><a href="javascript:' + this.name + '.toPage(1);">9</a></span>';
  160. strHtml += '<span title="Prev Page"><a href="javascript:' + this.name + '.toPage(' + prevPage + ');">7</a></span>';
  161. }
  162. if (nextPage > this.pageCount) {
  163. strHtml += '<span title="Next Page">8</span>';
  164. strHtml += '<span title="Last Page">:</span>';
  165. } else {
  166. strHtml += '<span title="Next Page"><a href="javascript:' + this.name + '.toPage(' + nextPage + ');">8</a></span>';
  167. strHtml += '<span title="Last Page"><a href="javascript:' + this.name + '.toPage(' + this.pageCount + ');">:</a></span>';
  168. }
  169. strHtml += '</span><br />';
  170. break;
  171. case 4 : //模式4 (下拉框)
  172. if (this.pageCount < 1) {
  173. strHtml += '<select name="toPage" disabled>';
  174. strHtml += '<option value="0">No Pages</option>';
  175. } else {
  176. var chkSelect;
  177. strHtml += '<select name="toPage" onchange="' + this.name + '.toPage(this);">';
  178. for (var i = 1; i <= this.pageCount; i++) {
  179. if (this.page == i) chkSelect=' selected="selected"';
  180. else chkSelect='';
  181. strHtml += '<option value="' + i + '"' + chkSelect + '>Pages: ' + i + ' / ' + this.pageCount + '</option>';
  182. }
  183. }
  184. strHtml += '</select>';
  185. break;
  186. case 5 : //模式5 (输入框)
  187. strHtml += '<span class="input">';
  188. if (this.pageCount < 1) {
  189. strHtml += '<input type="text" name="toPage" value="No Pages" class="itext" disabled="disabled">';
  190. strHtml += '<input type="button" name="go" value="GO" class="ibutton" disabled="disabled"></option>';
  191. } else {
  192. strHtml += '<input type="text" value="Input Page:" class="ititle" readonly="readonly">';
  193. strHtml += '<input type="text" id="pageInput' + this.showTimes + '" value="' + this.page + '" class="itext" title="Input page" onkeypress="return ' + this.name + '.formatInputPage(event);" onfocus="this.select()">';
  194. strHtml += '<input type="text" value=" / ' + this.pageCount + '" class="icount" readonly="readonly">';
  195. strHtml += '<input type="button" name="go" value="GO" class="ibutton" onclick="' + this.name + '.toPage(document.getElementById(/'pageInput' + this.showTimes + '/').value);"></option>';
  196. }
  197. strHtml += '</span>';
  198. break;
  199. default :
  200. strHtml = 'Javascript showPage Error: not find mode ' + mode;
  201. break;
  202. }
  203. return strHtml;
  204. }
  205. showPages.prototype.createUrl = function (page) { //生成页面跳转url
  206. if (isNaN(parseInt(page))) page = 1;
  207. if (page < 1) page = 1;
  208. if (page > this.pageCount) page = this.pageCount;
  209. var url = location.protocol + '//' + location.host + location.pathname;
  210. var args = location.search;
  211. var reg = new RegExp('([/?&]?)' + this.argName + '=[^&]*[&$]?', 'gi');
  212. args = args.replace(reg,'$1');
  213. if (args == '' || args == null) {
  214. args += '?' + this.argName + '=' + page;
  215. } else if (args.substr(args.length - 1,1) == '?' || args.substr(args.length - 1,1) == '&') {
  216. args += this.argName + '=' + page;
  217. } else {
  218. args += '&' + this.argName + '=' + page;
  219. }
  220. return url + args;
  221. }
  222. showPages.prototype.toPage = function(page){ //页面跳转
  223. var turnTo = 1;
  224. if (typeof(page) == 'object') {
  225. turnTo = page.options[page.selectedIndex].value;
  226. } else {
  227. turnTo = page;
  228. }
  229. self.location.href = this.createUrl(turnTo);
  230. }
  231. showPages.prototype.printHtml = function(mode){ //显示html代码
  232. this.getPage();
  233. this.checkPages();
  234. this.showTimes += 1;
  235. document.write('<div id="pages_' + this.name + '_' + this.showTimes + '" class="pages"></div>');
  236. document.getElementById('pages_' + this.name + '_' + this.showTimes).innerHTML = this.createHtml(mode);
  237. }
  238. showPages.prototype.formatInputPage = function(e){ //限定输入页数格式
  239. var ie = navigator.appName=="Microsoft Internet Explorer"?true:false;
  240. if(!ie) var key = e.which;
  241. else var key = event.keyCode;
  242. if (key == 8 || key == 46 || (key >= 48 && key <= 57)) return true;
  243. return false;
  244. }
  245. //-->
  246. </script>
  247. <style>
  248. /* Pages Main Tyle */
  249. .pages {
  250. color: #000000;
  251. cursor: default;
  252. font-size: 10px;
  253. font-family: Tahoma, Verdana;
  254. padding: 3px 0px 3px 0px;
  255. }
  256. .pages .count, .pages .number, .pages .arrow {
  257. color: #000000;
  258. font-size: 10px;
  259. background-color: #F7F7F7;
  260. border: 1px solid #CCCCCC;
  261. }
  262. /* Page and PageCount Style */
  263. .pages .count {
  264. font-weight: bold;
  265. border-right: none;
  266. padding: 2px 10px 1px 10px;
  267. }
  268. /* Mode 0,1,2 Style (Number) */
  269. .pages .number {
  270. font-weight: normal;
  271. padding: 2px 10px 1px 10px;
  272. }
  273. .pages .number a, .pages .number span {
  274. font-size: 10px;
  275. }
  276. .pages .number span {
  277. color: #999999;
  278. margin: 0px 3px 0px 3px;
  279. }
  280. .pages .number a {
  281. color: #000000;
  282. text-decoration: none;
  283. }
  284. .pages .number a:hover {
  285. color: #0000ff;
  286. }
  287. /* Mode 3 Style (Arrow) */
  288. .pages .arrow {
  289. font-weight: normal;
  290. padding: 0px 5px 0px 5px;
  291. }
  292. .pages .arrow a, .pages .arrow span {
  293. font-size: 10px;
  294. font-family: Webdings;
  295. }
  296. .pages .arrow span {
  297. color: #999999;
  298. margin: 0px 5px 0px 5px;
  299. }
  300. .pages .arrow a {
  301. color: #000000;
  302. text-decoration: none;
  303. }
  304. .pages .arrow a:hover {
  305. color: #0000ff;
  306. }
  307. /* Mode 4 Style (Select) */
  308. .pages select, .pages input {
  309. color: #000000;
  310. font-size: 10px;
  311. font-family: Tahoma, Verdana;
  312. }
  313. /* Mode 5 Style (Input) */
  314. .pages .input input.ititle, .pages .input input.itext, .pages .input input.icount {
  315. color: #666666;
  316. font-weight: bold;
  317. background-color: #F7F7F7;
  318. border: 1px solid #CCCCCC;
  319. }
  320. .pages .input input.ititle {
  321. width: 70px;
  322. text-align: right;
  323. border-right: none;
  324. }
  325. .pages .input input.itext {
  326. width: 25px;
  327. color: #000000;
  328. text-align: right;
  329. border-left: none;
  330. border-right: none;
  331. }
  332. .pages .input input.icount {
  333. width: 35px;
  334. text-align: left;
  335. border-left: none;
  336. }
  337. .pages .input input.ibutton {
  338. height: 17px;
  339. color: #FFFFFF;
  340. font-weight: bold;
  341. font-family: Verdana;
  342. background-color: #999999;
  343. border: 1px solid #666666;
  344. padding: 0px 0px 2px 1px;
  345. margin-left: 2px;
  346. cursor: hand;
  347. }
  348. /* body */
  349. body {
  350. font-size: 12px;
  351. }
  352. </style>
  353. </head>
  354. <body>
  355. <script language="JavaScript">
  356. <!--
  357. var pg = new showPages('pg');
  358. pg.pageCount =12;// 定义总页数(必要)
  359. //pg.argName = 'p';// 定义参数名(可选,默认为page)
  360. document.write('<br>Show Times: ' + pg.showTimes + ', Mood Default');
  361. pg.printHtml();
  362. document.write('<br>Show Times: ' + pg.showTimes + ', Mood 0');
  363. pg.printHtml(0);
  364. document.write('<br>Show Times: ' + pg.showTimes + ', Mood 1');
  365. pg.printHtml(1);
  366. document.write('<br>Show Times: ' + pg.showTimes + ', Mood 2');
  367. pg.printHtml(2);
  368. document.write('<br>Show Times: ' + pg.showTimes + ', Mood 3 (only IE)');
  369. pg.printHtml(3);
  370. document.write('<br>Show Times: ' + pg.showTimes + ', Mood 4');
  371. pg.printHtml(4);
  372. document.write('<br>Show Times: ' + pg.showTimes + ', Mood 5');
  373. pg.printHtml(5);
  374. //-->
  375. </script>
  376. </body>
  377. </html>
复制代码


九 DIV的透明层实现:


  1. <body bgcolor="#ff0ddd">
  2. <div id="Layer1" style="position:absolute; width:260px; height:115px; z-index:1; left: 50px; top: 77px; filter:Alpha(opacity=30)">
  3. <table width="96%" border="1" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#999999">
  4. <tr>
  5. <td height="25" bgcolor="#f5f5f5" class="13">你也可以在这里插入图片</td>
  6. </tr>
  7. <tr>
  8. <td height="20" bgcolor="#f5f5f5" class="12">你想注册地图名片吗</td>
  9. </tr>
  10. <tr>
  11. <td height="20" bgcolor="#f5f5f5" class="12">http://mc.mapabc.com</td>
  12. </tr>
  13. <tr>
  14. <td height="20" bgcolor="#f5f5f5" class="12">EMAIL:lipeng@mapabc.com</td>
  15. </tr>
  16. <tr>
  17. <td height="20" bgcolor="#f5f5f5" class="12">地址</td>
  18. </tr>
  19. <tr>
  20. <td height="20" bgcolor="#f5f5f5" class="12">邮编</td>
  21. </tr>
  22. </table>
  23. </div>
复制代码


十 超级强大的

表单

验证:


  1. <title>表单验证类 Validator v1.01</title>
  2. <style>
  3. body,td{font:normal 12px Verdana;color:#333333}
  4. input,textarea,select,td{font:normal 12px Verdana;color:#333333;border:1px solid #999999;background:#ffffff}
  5. table{border-collapse:collapse;}
  6. td{padding:3px}
  7. input{height:20;}
  8. textarea{width:80%;height:50px;overfmin:auto;}
  9. form{display:inline}
  10. </style>
  11. <table align="center">
  12. <form name="theForm" id="demo" action="" method="get" onSubmit="return Validator.Validate(this,2)">
  13. <tr>
  14. <td>真实姓名:</td><td><input name="Name" dataType="Chinese" msg="真实姓名只允许中文"></td>
  15. </tr>
  16. <tr>
  17. <td>英文名:</td><td><input name="Nick" dataType="English" require="false" msg="英文名只允许英文字母"></td>
  18. </tr>
  19. <tr>
  20. <td>主页:</td><td><input name="Homepage" require="false" dataType="Url" msg="非法的Url"></td>
  21. </tr>
  22. <tr>
  23. <td>密码:</td><td><input name="Password" dataType="SafeString" msg="密码不符合安全规则" type="password"></td>
  24. </tr>
  25. <tr>
  26. <td>重复:</td><td><input name="Repeat" dataType="Repeat" to="Password" msg="两次输入的密码不一致" type="password"></td>
  27. </tr>
  28. <tr>
  29. <td>信箱:</td><td><input name="Email" dataType="Email" msg="信箱格式不正确"></td>
  30. </tr>
  31. <tr>
  32. <td>信箱:</td><td><input name="Email" dataType="Repeat" to="Email" msg="两次输入的信箱不一致"></td>
  33. </tr>
  34. <tr>
  35. <td>QQ:</td><td><input name="QQ" require="false" dataType="QQ" msg="QQ号码不存在"></td>
  36. </tr>
  37. <tr>
  38. <td>身份证:</td><td><input name="Card" dataType="IdCard" msg="身份证号码不正确"></td>
  39. </tr>
  40. <tr>
  41. <td>年龄:</td><td><input name="Year" dataType="Range" msg="年龄必须在18~28之间" min="18" max="28"></td>
  42. </tr>
  43. <tr>
  44. <td>年龄1:</td><td><input name="Year1" require="false" dataType="Compare" msg="年龄必须在18以上" to="18" operator="GreaterThanEqual"></td>
  45. </tr>
  46. <tr>
  47. <td>电话:</td><td><input name="Phone" require="false" dataType="Phone" msg="电话号码不正确"></td>
  48. </tr>
  49. <tr>
  50. <td>手机:</td><td><input name="Mobile" require="false" dataType="Mobile" msg="手机号码不正确"></td>
  51. </tr>
  52. <tr>
  53. <td>生日:</td><td><input name="Birthday" dataType="Date" format="ymd" msg="生日日期不存在"></td>
  54. </tr>
  55. <tr>
  56. <td>邮政编码:</td><td><input name="Zip" dataType="Custom" regexp="^[1-9]/d{5}$" msg="邮政编码不存在"></td>
  57. </tr>
  58. <tr>
  59. <td>邮政编码:</td><td><input name="Zip1" dataType="Zip" msg="邮政编码不存在"></td>
  60. </tr>
  61. <tr>
  62. <td>操作系统:</td><td><select name="Operation" dataType="Require"msg="未选择所用操作系统" ><option value="">选择您所用的操作系统</option><option value="Win98">Win98</option><option value="Win2k">Win2k</option><option value="WinXP">WinXP</option></select></td>
  63. </tr>
  64. <tr>
  65. <td>所在省份:</td><td>广东<input name="Province" value="1" type="radio">陕西<input name="Province" value="2" type="radio">浙江<input name="Province" value="3" type="radio">江西<input name="Province" value="4" type="radio" dataType="Group"msg="必须选定一个省份" ></td>
  66. </tr>
  67. <tr>
  68. <td>爱好:</td><td>运动<input name="Favorite" value="1" type="checkbox">上网<input name="Favorite" value="2" type="checkbox">听音乐<input name="Favorite" value="3" type="checkbox">看书<input name="Favorite" value="4" type="checkbox"" dataType="Group" min="2" max="3"msg="必须选择2~3种爱好"></td>
  69. </tr>
  70. <td>自我介绍:</td><td><textarea name="Description" dataType="Limit" max="10"msg="自我介绍内容必须在10个字之内">中文是一个字</textarea></td>
  71. </tr>
  72. <td>自传:</td><td><textarea name="History" dataType="LimitB" min="3" max="10"msg="自传内容必须在[3,10]个字节之内">中文是两个字节t</textarea></td& gt;
  73. </tr>
  74. <tr>
  75. <td colspan="2"><input name="Submit" type="submit" value="确定提交"><input onClick="Validator.Validate(document.getElementById('demo'))" value="检验模式1" type="button"><input onClick="Validator.Validate(document.getElementById('demo'),2)" value="检验模式2" type="button"><input onClick="Validator.Validate(document.getElementById('demo'),3)" value="检验模式3" type="button"></td>
  76. </tr>
  77. </form>
  78. </table>
  79. <script>
  80. /*************************************************
  81. Validator v1.01
  82. code by 我佛山人
  83. wfsr@cunite.com
  84. http://www.cunite.com
  85. *************************************************/
  86. Validator = {
  87. Require : /.+/,
  88. Email : /^/w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*$/,
  89. Phone : /^((/(/d{3}/))|(/d{3}/-))?(/(0/d{2,3}/)|0/d{2,3}-)?[1-9]/d{6,7}$/,
  90. Mobile : /^((/(/d{3}/))|(/d{3}/-))?13/d{9}$/,
  91. Url : /^http:////[A-Za-z0-9]+/.[A-Za-z0-9]+[//=/?%/-&_~`@[/]/':+!]*([^<>/"/"])*$/,
  92. IdCard : /^/d{15}(/d{2}[A-Za-z0-9])?$/,
  93. Currency : /^/d+(/./d+)?$/,
  94. Number : /^/d+$/,
  95. Zip : /^[1-9]/d{5}$/,
  96. QQ : /^[1-9]/d{4,8}$/,
  97. Integer : /^[-/+]?/d+$/,
  98. Double : /^[-/+]?/d+(/./d+)?$/,
  99. English : /^[A-Za-z]+$/,
  100. Chinese :/^[/u0391-/uFFE5]+$/,
  101. UnSafe : /^(([A-Z]*|[a-z]*|/d*|[-_/~!@#/$%/^&/*/./(/)/[/]/{/}<>/?/////'/"]*)|.{0,5})$|/s/,
  102. IsSafe : function(str){return !this.UnSafe.test(str);},
  103. SafeString : "this.IsSafe(value)",
  104. Limit : "this.limit(value.length,getAttribute('min'),getAttribute('max'))",
  105. LimitB : "this.limit(this.LenB(value), getAttribute('min'), getAttribute('max'))",
  106. Date : "this.IsDate(value, getAttribute('min'), getAttribute('format'))",
  107. Repeat : "value == document.getElementsByName(getAttribute('to'))[0].value",
  108. Range : "getAttribute('min') < value && value < getAttribute('max')",
  109. Compare : "this.compare(value,getAttribute('operator'),getAttribute('to'))",
  110. Custom : "this.Exec(value, getAttribute('regexp'))",
  111. Group : "this.MustChecked(getAttribute('name'), getAttribute('min'), getAttribute('max'))",
  112. ErrorItem : [document.forms[0]],
  113. ErrorMessage : ["以下原因导致提交失败:/t/t/t/t"],
  114. Validate : function(theForm, mode){
  115. var obj = theForm || event.srcElement;
  116. var count = obj.elements.length;
  117. this.ErrorMessage.length = 1;
  118. this.ErrorItem.length = 1;
  119. this.ErrorItem[0] = obj;
  120. for(var i=0;i<count;i++){
  121. with(obj.elements[i]){
  122. var _dataType = getAttribute("dataType");
  123. if(typeof(_dataType) == "object" || typeof(this[_dataType]) == "undefined")continue;
  124. this.ClearState(obj.elements[i]);
  125. if(getAttribute("require") == "false" && value == "") continue;
  126. switch(_dataType){
  127. case "Date" :
  128. case "Repeat" :
  129. case "Range" :
  130. case "Compare" :
  131. case "Custom" :
  132. case "Group" :
  133. case "Limit" :
  134. case "LimitB" :
  135. case "SafeString" :
  136. if(!eval(this[_dataType])) {
  137. this.AddError(i, getAttribute("msg"));
  138. }
  139. break;
  140. default :
  141. if(!this[_dataType].test(value)){
  142. this.AddError(i, getAttribute("msg"));
  143. }
  144. break;
  145. }
  146. }
  147. }
  148. if(this.ErrorMessage.length > 1){
  149. mode = mode || 1;
  150. var errCount = this.ErrorItem.length;
  151. switch(mode){
  152. case 2 :
  153. for(var i=1;i<errCount;i++)
  154. this.ErrorItem[i].style.color = "red";
  155. case 1 :
  156. alert(this.ErrorMessage.join("/n"));
  157. this.ErrorItem[1].focus();
  158. break;
  159. case 3 :
  160. for(var i=1;i<errCount;i++){
  161. try{
  162. var span = document.createElement("SPAN");
  163. span.id = "__ErrorMessagePanel";
  164. span.style.color = "red";
  165. this.ErrorItem[i].parentNode.appendChild(span);
  166. span.innerHTML = this.ErrorMessage[i].replace(//d+:/,"*");
  167. }
  168. catch(e){alert(e.description);}
  169. }
  170. this.ErrorItem[1].focus();
  171. break;
  172. default :
  173. alert(this.ErrorMessage.join("/n"));
  174. break;
  175. }
  176. return false;
  177. }
  178. return true;
  179. },
  180. limit : function(len,min, max){
  181. min = min || 0;
  182. max = max || Number.MAX_VALUE;
  183. return min <= len && len <= max;
  184. },
  185. LenB : function(str){
  186. return str.replace(/[^/x00-/xff]/g,"**").length;
  187. },
  188. ClearState : function(elem){
  189. with(elem){
  190. if(style.color == "red")
  191. style.color = "";
  192. var lastNode = parentNode.childNodes[parentNode.childNodes.length-1];
  193. if(lastNode.id == "__ErrorMessagePanel")
  194. parentNode.removeChild(lastNode);
  195. }
  196. },
  197. AddError : function(index, str){
  198. this.ErrorItem[this.ErrorItem.length] = this.ErrorItem[0].elements[index];
  199. this.ErrorMessage[this.ErrorMessage.length] = this.ErrorMessage.length + ":" + str;
  200. },
  201. Exec : function(op, reg){
  202. return new RegExp(reg,"g").test(op);
  203. },
  204. compare : function(op1,operator,op2){
  205. switch (operator) {
  206. case "NotEqual":
  207. return (op1 != op2);
  208. case "GreaterThan":
  209. return (op1 > op2);
  210. case "GreaterThanEqual":
  211. return (op1 >= op2);
  212. case "LessThan":
  213. return (op1 < op2);
  214. case "LessThanEqual":
  215. return (op1 <= op2);
  216. default:
  217. return (op1 == op2);
  218. }
  219. },
  220. MustChecked : function(name, min, max){
  221. var groups = document.getElementsByName(name);
  222. var hasChecked = 0;
  223. min = min || 1;
  224. max = max || groups.length;
  225. for(var i=groups.length-1;i>=0;i--)
  226. if(groups[i].checked) hasChecked++;
  227. return min <= hasChecked && hasChecked <= max;
  228. },
  229. IsDate : function(op, formatString){
  230. formatString = formatString || "ymd";
  231. var m, year, month, day;
  232. switch(formatString){
  233. case "ymd" :
  234. m = op.match(new RegExp("^((//d{4})|(//d{2}))([-./])(//d{1,2})//4(//d{1,2})$"));
  235. if(m == null ) return false;
  236. day = m[6];
  237. month = m[5]--;
  238. year =(m[2].length == 4) ? m[2] : GetFullYear(parseInt(m[3], 10));
  239. break;
  240. case "dmy" :
  241. m = op.match(new RegExp("^(//d{1,2})([-./])(//d{1,2})//2((//d{4})|(//d{2}))$"));
  242. if(m == null ) return false;
  243. day = m[1];
  244. month = m[3]--;
  245. year = (m[5].length == 4) ? m[5] : GetFullYear(parseInt(m[6], 10));
  246. break;
  247. default :
  248. break;
  249. }
  250. if(!parseInt(month)) return false;
  251. month = month==12 ?0:month;
  252. var date = new Date(year, month, day);
  253. return (typeof(date) == "object" && year == date.getFullYear() && month == date.getMonth() && day == date.getDate());
  254. function GetFullYear(y){return ((y<30 ? "20" : "19") + y)|0;}
  255. }
  256. }
  257. </script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值