查看: 7266|回复: 0
打印 上一主题 下一主题

JavaScript经典效果集锦(转)

[复制链接]
跳转到指定楼层
1#
发表于 2007-10-6 11:23:18 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
台州网址导航
一 实用且必用的小脚本代码:

脚本1:进入主页以后自动播放声音
  1. [/code]脚本2:进入主页后自动最大话,省的去在自己单击了[code]
  2. self.moveTo(0,0)
  3. self.resizeTo(screen.availWidth,screen.availHeight)
复制代码
脚本3:显示现在时间的脚本
  1. document.write now
复制代码
脚本4:显示最后修改时间的脚本
  1. document.write(document.lastModified)
复制代码
脚本5:设为首页,加为收藏,加入频道,启动outlook发信
  1. <a style="cursor:hand" 
  2. onclick="this.style.behavior="url(#default#homepage)";
  3. this.setHomePage([url]http://10.13.31.90/~kayvin/);[/url]">">设为首页

  4. <a style="cursor:hand"
  5. onclick="window.external.AddFavorite(location.href,document.title);">加入收藏

  6. 加入频道

  7. 与我联系
复制代码
脚本6:状态栏动态显示现在时间

  1. function see(){
  2. window.setTimeout("see()",1000);
  3. today = new Date();
  4. self.status = today.toString();
  5. }

复制代码
脚本7:关闭窗口的脚本
  1. [关闭窗口]
复制代码
脚本8:按下F12键,直接返回首页
  1. 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}
复制代码
脚本9:后退,刷新,前进




复制代码
脚本10:设定时间弹出窗口,4000=4秒,当然你可以自定义
  1. function l()
  2. {
  3. window.open(" 10.13.31.90/~kayvin/ ","name","width=500,height=150,border=0")
  4. }
  5. setTimeout("l()",4000)

复制代码
二 鼠标旁边的提示信息,类似与163登录后的页面提示效果:
  1. tip

  2. //***********默认设置定义.*********************
  3. tPopWait=50;//停留tWait豪秒后显示提示。
  4. tPopShow=5000;//显示tShow豪秒后关闭提示
  5. showPopStep=20;
  6. popOpacity=99;
  7. //***************内部变量定义*****************
  8. sPop=null;
  9. curShow=null;
  10. tFadeOut=null;
  11. tFadeIn=null;
  12. tFadeWaiting=null;
  13. document.write("");
  14. 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)}");
  15. document.write("");
  16. document.write("");

  17. function showPopupText(){
  18. var o=event.srcElement;
  19. MouseX=event.x;
  20. MouseY=event.y;
  21. if(o.alt!=null && o.alt!=""){o.dypop=o.alt;o.alt=""};
  22. if(o.title!=null && o.title!=""){o.dypop=o.title;o.title=""};
  23. if(o.dypop!=sPop) {
  24. sPop=o.dypop;
  25. clearTimeout(curShow);
  26. clearTimeout(tFadeOut);
  27. clearTimeout(tFadeIn);
  28. clearTimeout(tFadeWaiting);
  29. if(sPop==null || sPop=="") {
  30. dypopLayer.innerHTML="";
  31. dypopLayer.style.filter="Alpha()";
  32. dypopLayer.filters.Alpha.opacity=0;
  33. }
  34. else {
  35. if(o.dyclass!=null) popStyle=o.dyclass
  36. else popStyle="cPopText";
  37. curShow=setTimeout("showIt()",tPopWait);
  38. }
  39. }
  40. }
  41. function showIt(){
  42. dypopLayer.className=popStyle;
  43. dypopLayer.innerHTML=sPop;
  44. popWidth=dypopLayer.clientWidth;
  45. popHeight=dypopLayer.clientHeight;
  46. if(MouseX+12+popWidth>document.body.clientWidth) popLeftAdjust=-popWidth-24
  47. else popLeftAdjust=0;
  48. if(MouseY+12+popHeight>document.body.clientHeight) popTopAdjust=-popHeight-24
  49. else popTopAdjust=0;
  50. dypopLayer.style.left=MouseX+12+document.body.scrollLeft+popLeftAdjust;
  51. dypopLayer.style.top=MouseY+12+document.body.scrollTop+popTopAdjust;
  52. dypopLayer.style.filter="Alpha(Opacity=0)";
  53. fadeOut();
  54. }
  55. function fadeOut(){
  56. if(dypopLayer.filters.Alpha.opacity<popOpacity) {
  57. dypopLayer.filters.Alpha.opacity+=showPopStep;
  58. tFadeOut=setTimeout("fadeOut()",1);
  59. }
  60. else {
  61. dypopLayer.filters.Alpha.opacity=popOpacity;
  62. tFadeWaiting=setTimeout("fadeIn()",tPopShow);
  63. }
  64. }
  65. function fadeIn(){
  66. if(dypopLayer.filters.Alpha.opacity>0) {
  67. dypopLayer.filters.Alpha.opacity-=1;
  68. tFadeIn=setTimeout("fadeIn()",1);
  69. }
  70. }
  71. document.onmouseover=showPopupText;
复制代码
三 如果文字过长,则将过长的部分变成省略号显示:
  1. <DIV STYLE="width: 120px; height: 50px; border: 1px solid blue;
  2.             overflow: hidden; text-overflow:ellipsis">
  3. 就是比如有一行文字,很长,表格内一行显示不下.
复制代码
四 滚动的图片

  1. imgArr=new Array()
  2. imgArr[0]=""
  3. imgArr[1]=""
  4. imgArr[2]=""
  5. imgArr[3]=""
  6. imgArr[4]=""

  7. var moveStep=4        //步长,单位:pixel
  8. var moveRelax=100    //移动时间间隔,单位:ms

  9. ns4=(document.layers)?true:false

  10. var displayImgAmount=4    //视区窗口可显示个数
  11. var divWidth=220    //每块图片占位宽
  12. var divHeight=145    //每块图片占位高

  13. var startDnum=0
  14. var nextDnum=startDnum+displayImgAmount
  15. var timeID
  16. var outHover=false

  17. var startDivClipLeft
  18. var nextDivClipRight

  19. function initDivPlace(){
  20.     if (ns4){
  21.         for (i=0;i<displayImgAmount;i++){
  22.             eval("document.divOuter.document.divAds"+i+".left="+divWidth*i)
  23.         }
  24.         for (i=displayImgAmount;i<imgArr.length;i++){
  25.             eval("document.divOuter.document.divAds"+i+".left="+divWidth*displayImgAmount)
  26.         }
  27.     }else{
  28.         for (i=0;i<displayImgAmount;i++){
  29.             eval("document.all.divAds"+i+".style.left="+divWidth*i)
  30.         }
  31.         for (i=displayImgAmount;i<imgArr.length;i++){
  32.             eval("document.all.divAds"+i+".style.left="+divWidth*displayImgAmount)
  33.         }
  34.     }
  35. }

  36. function mvStart(){
  37.     timeID=setTimeout(moveLeftDiv,moveRelax)
  38. }

  39. function mvStop(){
  40.     clearTimeout(timeID)
  41. }

  42. function moveLeftDiv(){
  43.     if (ns4){
  44.         for (i=0;i<=displayImgAmount;i++){
  45.             eval("document.divOuter.document.divAds"+parseInt((startDnum+i)%imgArr.length)+".left=document.divOuter.document.divAds"+parseInt((startDnum+i)%imgArr.length)+".left-moveStep")
  46.         }

  47.         startDivClipLeft=parseInt(eval("document.divOuter.document.divAds"+startDnum+".clip.left"))
  48.         nextDivClipRight=parseInt(eval("document.divOuter.document.divAds"+nextDnum+".clip.right"))

  49.         if (startDivClipLeft+moveStep>divWidth){
  50.             eval("document.divOuter.document.divAds"+nextDnum+".clip.right="+divWidth)
  51.             
  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.             
  56.             
  57.             startDnum=(++startDnum)%imgArr.length
  58.             nextDnum=(startDnum+displayImgAmount)%imgArr.length
  59.             
  60.             startDivClipLeft=moveStep-(divWidth-startDivClipLeft)
  61.             nextDivClipRight=moveStep-(divWidth-nextDivClipRight)
  62.         }else{
  63.             eval("document.divOuter.document.divAds"+nextDnum+".clip.left=0")
  64.             startDivClipLeft+=moveStep
  65.             nextDivClipRight+=moveStep
  66.         }
  67.         eval("document.divOuter.document.divAds"+startDnum+".clip.left="+startDivClipLeft)
  68.         eval("document.divOuter.document.divAds"+nextDnum+".clip.right="+nextDivClipRight)
  69.     }else{
  70.         for (i=0;i<=displayImgAmount;i++){
  71.             eval("document.all.divAds"+parseInt((startDnum+i)%imgArr.length)+".style.left=document.all.divAds"+parseInt((startDnum+i)%imgArr.length)+".style.pixelLeft-moveStep")
  72.         }
  73.    
  74.         startDivClipLeft=parseInt(eval("document.all.divAds"+startDnum+".currentStyle.clipLeft"))
  75.         nextDivClipRight=parseInt(eval("document.all.divAds"+nextDnum+".currentStyle.clipRight"))
  76.    
  77.         if (startDivClipLeft+moveStep>divWidth){
  78.             eval("document.all.divAds"+nextDnum+".style.clip='rect(0,"+divWidth+","+divHeight+",0"+")'")
  79.             
  80.             eval("document.all.divAds"+startDnum+".style.left="+divWidth*displayImgAmount)
  81.             eval("document.all.divAds"+parseInt((nextDnum+1)%imgArr.length)+".style.left=document.all.divAds"+nextDnum+".style.pixelLeft+"+divWidth)
  82.             
  83.             startDnum=(++startDnum)%imgArr.length
  84.             nextDnum=(startDnum+displayImgAmount)%imgArr.length
  85.             
  86.             startDivClipLeft=moveStep-(divWidth-startDivClipLeft)
  87.             nextDivClipRight=moveStep-(divWidth-nextDivClipRight)
  88.         }else{
  89.             startDivClipLeft+=moveStep
  90.             nextDivClipRight+=moveStep
  91.         }
  92.         eval("document.all.divAds"+startDnum+".style.clip='rect(0,"+divWidth+","+divHeight+","+startDivClipLeft+")'")
  93.         eval("document.all.divAds"+nextDnum+".style.clip='rect(0,"+nextDivClipRight+","+divHeight+",0)'")
  94.     }

  95.     if (outHover){
  96.         mvStop()
  97.     }else{
  98.         mvStart()
  99.     }
  100.    
  101.    
  102. }

  103. function writeDivs(){
  104.     if (ns4){
  105.         document.write("")
  106.         
  107.         for (i=0;i<imgArr.length;i++){
  108.             document.write("")
  109.             document.write(imgArr[i]+" ")
  110.             document.write("")
  111.         }
  112.         document.write("")
  113.         document.close()
  114.         for (i=displayImgAmount;i<imgArr.length;i++){
  115.             eval("document.divOuter.document.divAds"+i+".clip.right=0")
  116.         }
  117.     }else{
  118.         document.write("")
  119.         
  120.         for (i=0;i<imgArr.length;i++){
  121.             document.write("")
  122.             document.write(imgArr[i]+" ")
  123.             document.write("")
  124.         }
  125.         document.write("")
  126.         for (i=displayImgAmount;i<imgArr.length;i++){
  127.             eval("document.all.divAds"+i+".style.clip='rect(0,0,"+divHeight+",0)'")
  128.         }
  129.     }
  130. }


  131. writeDivs();initDivPlace();
复制代码
五 接收键盘指令的脚本:

  1. <!--
  2. var hotkey=97
  3. var destination="http://www.wyev.com"
  4. if (document.layers)
  5. document.captureEvents(Event.KEYPRESS)
  6. function backhome(e){
  7. if (document.layers){
  8. if (e.which==hotkey)
  9. window.location=destination
  10. }
  11. else if (document.all){
  12. if (event.keyCode==hotkey)
  13. window.location=destination
  14. }
  15. }
  16. document.onkeypress=backhome
  17. //-->



  18. onkeydown="javascript:onenter();"

  19. function onenter(){
  20. if(event.keyCode==13){
  21. alert("回车");
  22. }
  23. }
复制代码
六 让你的文本链接渐隐渐显:







  1. startColor = "#671700"; // 定义链接颜色
  2. endColor = "#D8D1C5";  // 定义要渐变到最后的颜色

  3. stepIn = 17;
  4. stepOut = 23;

  5. /*
  6. 定义是否让所有的文本链接自动渐变,true为是,false为否
  7. */
  8. autoFade = true;  

  9. /*
  10. 在这里定义css样式里的类class:fade,如果为true,那么你要将要渐变的链接上加上此fade样式
  11. */
  12. sloppyClass = false;

  13. hexa = new makearray(16);
  14. for(var i = 0; i < 10; i++)
  15.     hexa[i] = i;
  16. hexa[10]="a"; hexa[11]="b"; hexa[12]="c";
  17. hexa[13]="d"; hexa[14]="e"; hexa[15]="f";

  18. document.onmouseover = domouseover;
  19. document.onmouseout = domouseout;

  20. startColor = dehexize(startColor.toLowerCase());
  21. endColor = dehexize(endColor.toLowerCase());

  22. var fadeId = new Array();

  23. function dehexize(Color){
  24. var colorArr = new makearray(3);
  25. for (i=1; i<7; i++){
  26.   for (j=0; j<16; j++){
  27.    if (Color.charAt(i) == hexa[j]){
  28.     if (i%2 !=0)
  29.      colorArr[Math.floor((i-1)/2)]=eval(j)*16;
  30.     else
  31.      colorArr[Math.floor((i-1)/2)]+=eval(j);
  32.    }
  33.   }
  34. }
  35. return colorArr;
  36. }

  37. function domouseover() {
  38.   if(document.all){
  39.    var srcElement = event.srcElement;
  40.    if ((srcElement.tagName == "A" && autoFade) || srcElement.className == "fade" || (sloppyClass && srcElement.className.indexOf("fade") != -1))
  41.         fade(startColor,endColor,srcElement.uniqueID,stepIn);      
  42.    }
  43. }

  44. function domouseout() {
  45.   if (document.all){
  46.    var srcElement = event.srcElement;
  47.     if ((srcElement.tagName == "A" && autoFade) || srcElement.className == "fade" || (sloppyClass && srcElement.className.indexOf("fade") != -1))
  48.         fade(endColor,startColor,srcElement.uniqueID,stepOut);
  49.     }
  50. }

  51. function makearray(n) {
  52.     this.length = n;
  53.     for(var i = 1; i <= n; i++)
  54.         this[i] = 0;
  55.     return this;
  56. }

  57. function hex(i) {
  58.     if (i < 0)
  59.         return "00";
  60.     else if (i > 255)
  61.         return "ff";
  62.     else
  63.        return "" + hexa[Math.floor(i/16)] + hexa[i%16];}

  64. function setColor(r, g, b, element) {
  65.       var hr = hex(r); var hg = hex(g); var hb = hex(b);
  66.       element.style.color = "#"+hr+hg+hb;
  67. }

  68. function fade(s,e, element,step){
  69. var sr = s[0]; var sg = s[1]; var sb = s[2];
  70. var er = e[0]; var eg = e[1]; var eb = e[2];

  71. if (fadeId[0] != null && fade[0] != element){
  72.   setColor(sr,sg,sb,eval(fadeId[0]));
  73.   var i = 1;
  74.   while(i < fadeId.length){
  75.    clearTimeout(fadeId[i]);
  76.    i++;
  77.    }
  78.   }
  79.   
  80.     for(var i = 0; i <= step; i++) {
  81.      fadeId[i+1] = setTimeout("setColor(Math.floor(" +sr+ " *(( " +step+ " - " +i+ " )/ " +step+ " ) + " +er+ " * (" +i+ "/" +
  82.    step+ ")),Math.floor(" +sg+ " * (( " +step+ " - " +i+ " )/ " +step+ " ) + " +eg+ " * (" +i+ "/" +step+
  83.    ")),Math.floor(" +sb+ " * ((" +step+ "-" +i+ ")/" +step+ ") + " +eb+ " * (" +i+ "/" +step+ ")),"+element+");",i*step);
  84.   }
  85. fadeId[0] = element;
  86. }





  87. 让你的文本链接渐隐渐显[c/ode]
  88. 七 类似与QQ的好友/黑名单之类的树型菜单_极品:

  89. [code]
  90. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">


  91. New Document








  92. if (!document.getElementById)
  93.     document.getElementById = function() { return null; }

  94. function initializeMenu(menuId, actuatorId) {
  95.     var menu = document.getElementById(menuId);
  96.     var actuator = document.getElementById(actuatorId);

  97.     if (menu == null || actuator == null) return;

  98.     //if (window.opera) return; // I'm too tired

  99.     actuator.parentNode.style.backgroundImage = "url(/images/plus.gif)";
  100.     actuator.onclick = function() {
  101.         var display = menu.style.display;
  102.         this.parentNode.style.backgroundImage =
  103.             (display == "block") ? "url(/images/plus.gif)" : "url(/images/minus.gif)";
  104.         menu.style.display = (display == "block") ? "none" : "block";

  105.         return false;
  106.     }
  107. }
  108. window.onload = function() {
  109.             initializeMenu("productsMenu", "productsActuator");
  110.             initializeMenu("newPhonesMenu", "newPhonesActuator");
  111.             initializeMenu("compareMenu", "compareActuator");
  112.         }


  113. body {
  114.   font-family: verdana, helvetica, arial, sans-serif;
  115. }

  116. #mainMenu {
  117.   background-color: #EEE;
  118.   border: 1px solid #CCC;
  119.   color: #000;
  120.   width: 203px;
  121. }

  122. #menuList {
  123.   margin: 0px;
  124.   padding: 10px 0px 10px 15px;
  125. }

  126. li.menubar {
  127.   background: url(/images/plus.gif) no-repeat 0em 0.3em;
  128.   font-size: 12px;
  129.   line-height: 1.5em;
  130.   list-style: none outside;
  131. }

  132. .menu, .submenu {
  133.   display: none;
  134.   margin-left: 15px;
  135.   padding: 0px;
  136. }

  137. .menu li, .submenu li {
  138.   background: url(/images/square.gif) no-repeat 0em 0.3em;
  139.   list-style: none outside;
  140. }

  141. a.actuator {
  142.   background-color: transparent;
  143.   color: #000;
  144.   font-size: 12px;
  145.   padding-left: 15px;
  146.   text-decoration: none;
  147. }

  148. a.actuator:hover {
  149.   text-decoration: underline;
  150. }

  151. .menu li a, .submenu li a {
  152.   background-color: transparent;
  153.   color: #000;
  154.   font-size: 12px;
  155.   padding-left: 15px;
  156.   text-decoration: none;
  157. }

  158. .menu li a:hover, submenu li a:hover {
  159.   /*border-bottom: 1px dashed #000;*/
  160.   text-decoration: underline;
  161. }

  162. span.key {
  163.   text-decoration: underline;
  164. }




  165.       
  166.         
  167.           图秀地带收藏夹
  168.          
  169.             
  170.               我的好友
  171.               
  172.                 张三[10000001]
  173.                 李四[10000002]
  174.                 张三[10000001]
  175.                 李四[10000002]
  176.               
  177.             
  178.             
  179.               陌生人
  180.               
  181.                 张三[10000001]
  182.                 李四[10000002]
  183.                 张三[10000001]
  184.                 李四[10000002]
  185.               
  186.             
  187.          
  188.         
  189.       
  190.    
  191.   

复制代码
八 很多的脚本翻页:
  1. <!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



  2. JavaScript: showPages v1.0 [by Lapuasi.com]

  3. <!--
  4. /*

  5. showPages v1.1
  6. =================================

  7. Infomation
  8. ----------------------
  9. Author : Lapuasi
  10. E-Mail : [email]lapuasi@gmail.com[/email]
  11. Web : [url]http://www.lapuasi.com[/url]
  12. Date : 2005-11-17


  13. Example
  14. ----------------------
  15. var pg = new showPages('pg');
  16. pg.pageCount = 12; //定义总页数(必要)
  17. pg.argName = 'p';    //定义参数名(可选,缺省为page)
  18. pg.printHtml();        //显示页数


  19. Supported in Internet Explorer, Mozilla Firefox
  20. */

  21. function showPages(name) { //初始化属性
  22.         this.name = name;      //对象名称
  23.         this.page = 1;         //当前页数
  24.         this.pageCount = 1;    //总页数
  25.         this.argName = 'page'; //参数名
  26.         this.showTimes = 1;    //打印次数
  27. }

  28. showPages.prototype.getPage = function(){ //丛url获得当前页数,如果变量重复只获取最后一个
  29.         var args = location.search;
  30.         var reg = new RegExp('[\?&]?' + this.argName + '=([^&]*)[&$]?', 'gi');
  31.         var chk = args.match(reg);
  32.         this.page = RegExp.$1;
  33. }
  34. showPages.prototype.checkPages = function(){ //进行当前页数和总页数的验证
  35.         if (isNaN(parseInt(this.page))) this.page = 1;
  36.         if (isNaN(parseInt(this.pageCount))) this.pageCount = 1;
  37.         if (this.page < 1) this.page = 1;
  38.         if (this.pageCount < 1) this.pageCount = 1;
  39.         if (this.page > this.pageCount) this.page = this.pageCount;
  40.         this.page = parseInt(this.page);
  41.         this.pageCount = parseInt(this.pageCount);
  42. }
  43. showPages.prototype.createHtml = function(mode){ //生成html代码
  44.         var strHtml = '', prevPage = this.page - 1, nextPage = this.page + 1;
  45.         if (mode == '' || typeof(mode) == 'undefined') mode = 0;
  46.         switch (mode) {
  47.                 case 0 : //模式1 (页数,首页,前页,后页,尾页)
  48.                         strHtml += 'Pages: ' + this.page + ' / ' + this.pageCount + '';
  49.                         strHtml += '';
  50.                         if (prevPage < 1) {
  51.                                 strHtml += '&laquo;';
  52.                                 strHtml += '‹';
  53.                         } else {
  54.                                 strHtml += '&laquo;';
  55.                                 strHtml += '‹';
  56.                         }
  57.                         for (var i = 1; i <= this.pageCount; i++) {
  58.                                 if (i > 0) {
  59.                                         if (i == this.page) {
  60.                                                 strHtml += '[' + i + ']';
  61.                                         } else {
  62.                                                 strHtml += '[' + i + ']';
  63.                                         }
  64.                                 }
  65.                         }
  66.                         if (nextPage > this.pageCount) {
  67.                                 strHtml += '›';
  68.                                 strHtml += '&raquo;';
  69.                         } else {
  70.                                 strHtml += '›';
  71.                                 strHtml += '&raquo;';
  72.                         }
  73.                         strHtml += '
  74. ';
  75.                         break;
  76.                 case 1 : //模式1 (10页缩略,首页,前页,后页,尾页)
  77.                         strHtml += 'Pages: ' + this.page + ' / ' + this.pageCount + '';
  78.                         strHtml += '';
  79.                         if (prevPage < 1) {
  80.                                 strHtml += '&laquo;';
  81.                                 strHtml += '‹';
  82.                         } else {
  83.                                 strHtml += '&laquo;';
  84.                                 strHtml += '‹';
  85.                         }
  86.                         if (this.page % 10 ==0) {
  87.                                 var startPage = this.page - 9;
  88.                         } else {
  89.                                 var startPage = this.page - this.page % 10 + 1;
  90.                         }
  91.                         if (startPage > 10) strHtml += '...';
  92.                         for (var i = startPage; i < startPage + 10; i++) {
  93.                                 if (i > this.pageCount) break;
  94.                                 if (i == this.page) {
  95.                                         strHtml += '[' + i + ']';
  96.                                 } else {
  97.                                         strHtml += '[' + i + ']';
  98.                                 }
  99.                         }
  100.                         if (this.pageCount >= startPage + 10) strHtml += '...';
  101.                         if (nextPage > this.pageCount) {
  102.                                 strHtml += '›';
  103.                                 strHtml += '&raquo;';
  104.                         } else {
  105.                                 strHtml += '›';
  106.                                 strHtml += '&raquo;';
  107.                         }
  108.                         strHtml += '
  109. ';
  110.                         break;
  111.                 case 2 : //模式2 (前后缩略,页数,首页,前页,后页,尾页)
  112.                         strHtml += 'Pages: ' + this.page + ' / ' + this.pageCount + '';
  113.                         strHtml += '';
  114.                         if (prevPage < 1) {
  115.                                 strHtml += '&laquo;';
  116.                                 strHtml += '‹';
  117.                         } else {
  118.                                 strHtml += '&laquo;';
  119.                                 strHtml += '‹';
  120.                         }
  121.                         if (this.page != 1) strHtml += '[1]';
  122.                         if (this.page >= 5) strHtml += '...';
  123.                         if (this.pageCount > this.page + 2) {
  124.                                 var endPage = this.page + 2;
  125.                         } else {
  126.                                 var endPage = this.pageCount;
  127.                         }
  128.                         for (var i = this.page - 2; i <= endPage; i++) {
  129.                                 if (i > 0) {
  130.                                         if (i == this.page) {
  131.                                                 strHtml += '[' + i + ']';
  132.                                         } else {
  133.                                                 if (i != 1 && i != this.pageCount) {
  134.                                                         strHtml += '[' + i + ']';
  135.                                                 }
  136.                                         }
  137.                                 }
  138.                         }
  139.                         if (this.page + 3 < this.pageCount) strHtml += '...';
  140.                         if (this.page != this.pageCount) strHtml += '[' + this.pageCount + ']';
  141.                         if (nextPage > this.pageCount) {
  142.                                 strHtml += '›';
  143.                                 strHtml += '&raquo;';
  144.                         } else {
  145.                                 strHtml += '›';
  146.                                 strHtml += '&raquo;';
  147.                         }
  148.                         strHtml += '
  149. ';
  150.                         break;
  151.                 case 3 : //模式3 (箭头样式,首页,前页,后页,尾页) (only IE)
  152.                         strHtml += 'Pages: ' + this.page + ' / ' + this.pageCount + '';
  153.                         strHtml += '';
  154.                         if (prevPage < 1) {
  155.                                 strHtml += '9';
  156.                                 strHtml += '7';
  157.                         } else {
  158.                                 strHtml += '9';
  159.                                 strHtml += '7';
  160.                         }
  161.                         if (nextPage > this.pageCount) {
  162.                                 strHtml += '8';
  163.                                 strHtml += ':';
  164.                         } else {
  165.                                 strHtml += '8';
  166.                                 strHtml += ':';
  167.                         }
  168.                         strHtml += '
  169. ';
  170.                         break;
  171.                 case 4 : //模式4 (下拉框)
  172.                         if (this.pageCount < 1) {
  173.                                 strHtml += '';
  174.                                 strHtml += 'No Pages';
  175.                         } else {
  176.                                 var chkSelect;
  177.                                 strHtml += '';
  178.                                 for (var i = 1; i <= this.pageCount; i++) {
  179.                                         if (this.page == i) chkSelect=' selected="selected"';
  180.                                         else chkSelect='';
  181.                                         strHtml += 'Pages: ' + i + ' / ' + this.pageCount + '';
  182.                                 }
  183.                         }
  184.                         strHtml += '';
  185.                         break;
  186.                 case 5 : //模式5 (输入框)
  187.                         strHtml += '';
  188.                         if (this.pageCount < 1) {
  189.                                 strHtml += '';
  190.                                 strHtml += '';
  191.                         } else {
  192.                                 strHtml += '';
  193.                                 strHtml += '';
  194.                                 strHtml += '';
  195.                                 strHtml += '';
  196.                         }
  197.                         strHtml += '';
  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('');
  236.         document.getElementById('pages_' + this.name + '_' + this.showTimes).innerHTML = this.createHtml(mode);
  237.         
  238. }
  239. showPages.prototype.formatInputPage = function(e){ //限定输入页数格式
  240.         var ie = navigator.appName=="Microsoft Internet Explorer"?true:false;
  241.         if(!ie) var key = e.which;
  242.         else var key = event.keyCode;
  243.         if (key == 8 || key == 46 || (key >= 48 && key <= 57)) return true;
  244.         return false;
  245. }
  246. //-->


  247. /* Pages Main Tyle */
  248. .pages {
  249.         color: #000000;
  250.         cursor: default;
  251.         font-size: 10px;
  252.         font-family: Tahoma, Verdana;
  253.         padding: 3px 0px 3px 0px;
  254. }
  255. .pages .count, .pages .number, .pages .arrow {
  256.         color: #000000;
  257.         font-size: 10px;
  258.         background-color: #F7F7F7;
  259.         border: 1px solid #CCCCCC;
  260. }
  261. /* Page and PageCount Style */
  262. .pages .count {
  263.         font-weight: bold;
  264.         border-right: none;
  265.         padding: 2px 10px 1px 10px;
  266. }
  267. /* Mode 0,1,2 Style (Number) */
  268. .pages .number {
  269.         font-weight: normal;
  270.         padding: 2px 10px 1px 10px;
  271. }
  272. .pages .number a, .pages .number span {
  273.         font-size: 10px;
  274. }
  275. .pages .number span {
  276.         color: #999999;
  277.         margin: 0px 3px 0px 3px;
  278. }
  279. .pages .number a {
  280.         color: #000000;
  281.         text-decoration: none;
  282. }
  283. .pages .number a:hover {
  284.         color: #0000ff;
  285. }
  286. /* Mode 3 Style (Arrow) */
  287. .pages .arrow {
  288.         font-weight: normal;
  289.         padding: 0px 5px 0px 5px;
  290. }
  291. .pages .arrow a, .pages .arrow span {
  292.         font-size: 10px;
  293.         font-family: Webdings;
  294. }
  295. .pages .arrow span {
  296.         color: #999999;
  297.         margin: 0px 5px 0px 5px;
  298. }
  299. .pages .arrow a {
  300.         color: #000000;
  301.         text-decoration: none;
  302. }
  303. .pages .arrow a:hover {
  304.         color: #0000ff;
  305. }
  306. /* Mode 4 Style (Select) */
  307. .pages select, .pages input {
  308.         color: #000000;
  309.         font-size: 10px;
  310.         font-family: Tahoma, Verdana;
  311. }
  312. /* Mode 5 Style (Input) */
  313. .pages .input input.ititle, .pages .input input.itext, .pages .input input.icount {
  314.         color: #666666;
  315.         font-weight: bold;
  316.         background-color: #F7F7F7;
  317.         border: 1px solid #CCCCCC;
  318. }
  319. .pages .input input.ititle {
  320.         width: 70px;
  321.         text-align: right;
  322.         border-right: none;
  323. }
  324. .pages .input input.itext {
  325.         width: 25px;
  326.         color: #000000;
  327.         text-align: right;
  328.         border-left: none;
  329.         border-right: none;
  330. }
  331. .pages .input input.icount {
  332.         width: 35px;
  333.         text-align: left;
  334.         border-left: none;
  335. }
  336. .pages .input input.ibutton {
  337.         height: 17px;
  338.         color: #FFFFFF;
  339.         font-weight: bold;
  340.         font-family: Verdana;
  341.         background-color: #999999;
  342.         border: 1px solid #666666;
  343.         padding: 0px 0px 2px 1px;
  344.         margin-left: 2px;
  345.         cursor: hand;
  346. }

  347. /* body */
  348. body {
  349.         font-size: 12px;
  350. }





  351. <!--
  352. var pg = new showPages('pg');
  353. pg.pageCount =12;  // 定义总页数(必要)
  354. //pg.argName = 'p';  // 定义参数名(可选,默认为page)

  355. document.write('
  356. Show Times: ' + pg.showTimes + ', Mood Default');
  357. pg.printHtml();
  358. document.write('
  359. Show Times: ' + pg.showTimes + ', Mood 0');
  360. pg.printHtml(0);
  361. document.write('
  362. Show Times: ' + pg.showTimes + ', Mood 1');
  363. pg.printHtml(1);
  364. document.write('
  365. Show Times: ' + pg.showTimes + ', Mood 2');
  366. pg.printHtml(2);
  367. document.write('
  368. Show Times: ' + pg.showTimes + ', Mood 3 (only IE)');
  369. pg.printHtml(3);
  370. document.write('
  371. Show Times: ' + pg.showTimes + ', Mood 4');
  372. pg.printHtml(4);
  373. document.write('
  374. Show Times: ' + pg.showTimes + ', Mood 5');
  375. pg.printHtml(5);
  376. //-->


复制代码
九 DIV的透明层实现:


  1.         
  2.            
  3.                                 
  4.             你也可以在这里插入图片
  5.                               
  6.                               
  7.                                 
  8.             你想注册地图名片吗
  9.                               
  10.                               
  11.                                 
  12.             [url]http://mc.mapabc.com[/url]
  13.                               
  14.                               
  15.                                 
  16.             EMAIL:lipeng@mapabc.com
  17.                               
  18.                               
  19.                                 
  20.             地址
  21.                               
  22.                               
  23.                                 
  24.             邮编
  25.                               
  26.                            
  27.               
复制代码
十 超级强大的表单验证:
  1. 表单验证类 Validator v1.01

  2. body,td{font:normal 12px Verdana;color:#333333}
  3. input,textarea,select,td{font:normal 12px Verdana;color:#333333;border:1px solid #999999;background:#ffffff}
  4. table{border-collapse:collapse;}
  5. td{padding:3px}
  6. input{height:20;}
  7. textarea{width:80%;height:50px;overfmin:auto;}
  8. form{display:inline}


  9.   
  10.    
  11.    真实姓名:
  12.   
  13.   
  14.    英文名:
  15.   
  16.    
  17.    主页:
  18.   
  19.   
  20.    密码:
  21.   
  22.   
  23.    重复:
  24.   
  25.   
  26.    信箱:
  27.   
  28.    
  29.    信箱:
  30.   
  31.   
  32.    QQ:
  33.   
  34.    
  35.    身份证:
  36.   
  37.   
  38.    年龄:
  39.   
  40.    
  41.    年龄1:
  42.   
  43.    
  44.    电话:
  45.   
  46.    
  47.    手机:
  48.   
  49.      
  50.    生日:
  51.   
  52.    
  53.    邮政编码:
  54.   
  55.   
  56.    邮政编码:
  57.   
  58.   
  59.    操作系统:选择您所用的操作系统Win98Win2kWinXP
  60.   
  61.   
  62.    所在省份:广东陕西浙江江西
  63.   
  64.   
  65.    爱好:运动上网听音乐看书
  66.   
  67.    自我介绍:中文是一个字
  68.   
  69.      自传:中文是两个字节t
  70.   
  71.   
  72.    
  73.   
  74.   


  75. /*************************************************
  76.         Validator v1.01
  77.         code by 我佛山人
  78.         [email]wfsr@cunite.com[/email]
  79.         [url]http://www.cunite.com[/url]
  80. *************************************************/
  81. Validator = {
  82.         Require : /.+/,
  83.         Email : /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
  84.         Phone : /^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$/,
  85.         Mobile : /^((\(\d{3}\))|(\d{3}\-))?13\d{9}$/,
  86.         Url : /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/,
  87.         IdCard : /^\d{15}(\d{2}[A-Za-z0-9])?$/,
  88.         Currency : /^\d+(\.\d+)?$/,
  89.         Number : /^\d+$/,
  90.         Zip : /^[1-9]\d{5}$/,
  91.         QQ : /^[1-9]\d{4,8}$/,
  92.         Integer : /^[-\+]?\d+$/,
  93.         Double : /^[-\+]?\d+(\.\d+)?$/,
  94.         English : /^[A-Za-z]+$/,
  95.         Chinese :  /^[\u0391-\uFFE5]+$/,
  96.         UnSafe : /^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.{0,5})$|\s/,
  97.         IsSafe : function(str){return !this.UnSafe.test(str);},
  98.         SafeString : "this.IsSafe(value)",
  99.         Limit : "this.limit(value.length,getAttribute('min'),  getAttribute('max'))",
  100.         LimitB : "this.limit(this.LenB(value), getAttribute('min'), getAttribute('max'))",
  101.         Date : "this.IsDate(value, getAttribute('min'), getAttribute('format'))",
  102.         Repeat : "value == document.getElementsByName(getAttribute('to'))[0].value",
  103.         Range : "getAttribute('min') < value && value < getAttribute('max')",
  104.         Compare : "this.compare(value,getAttribute('operator'),getAttribute('to'))",
  105.         Custom : "this.Exec(value, getAttribute('regexp'))",
  106.         Group : "this.MustChecked(getAttribute('name'), getAttribute('min'), getAttribute('max'))",
  107.         ErrorItem : [document.forms[0]],
  108.         ErrorMessage : ["以下原因导致提交失败:\t\t\t\t"],
  109.         Validate : function(theForm, mode){
  110.                 var obj = theForm || event.srcElement;
  111.                 var count = obj.elements.length;
  112.                 this.ErrorMessage.length = 1;
  113.                 this.ErrorItem.length = 1;
  114.                 this.ErrorItem[0] = obj;
  115.                 for(var i=0;i<count;i++){
  116.                         with(obj.elements[i]){
  117.                                 var _dataType = getAttribute("dataType");
  118.                                 if(typeof(_dataType) == "object" || typeof(this[_dataType]) == "undefined")  continue;
  119.                                 this.ClearState(obj.elements[i]);
  120.                                 if(getAttribute("require") == "false" && value == "") continue;
  121.                                 switch(_dataType){
  122.                                         case "Date" :
  123.                                         case "Repeat" :
  124.                                         case "Range" :
  125.                                         case "Compare" :
  126.                                         case "Custom" :
  127.                                         case "Group" :
  128.                                         case "Limit" :
  129.                                         case "LimitB" :
  130.                                         case "SafeString" :
  131.                                                 if(!eval(this[_dataType]))        {
  132.                                                         this.AddError(i, getAttribute("msg"));
  133.                                                 }
  134.                                                 break;
  135.                                         default :
  136.                                                 if(!this[_dataType].test(value)){
  137.                                                         this.AddError(i, getAttribute("msg"));
  138.                                                 }
  139.                                                 break;
  140.                                 }
  141.                         }
  142.                 }
  143.                 if(this.ErrorMessage.length > 1){
  144.                         mode = mode || 1;
  145.                         var errCount = this.ErrorItem.length;
  146.                         switch(mode){
  147.                         case 2 :
  148.                                 for(var i=1;i<errCount;i++)
  149.                                         this.ErrorItem[i].style.color = "red";
  150.                         case 1 :
  151.                                 alert(this.ErrorMessage.join("\n"));
  152.                                 this.ErrorItem[1].focus();
  153.                                 break;
  154.                         case 3 :
  155.                                 for(var i=1;i<errCount;i++){
  156.                                 try{
  157.                                         var span = document.createElement("SPAN");
  158.                                         span.id = "__ErrorMessagePanel";
  159.                                         span.style.color = "red";
  160.                                         this.ErrorItem[i].parentNode.appendChild(span);
  161.                                         span.innerHTML = this.ErrorMessage[i].replace(/\d+:/,"*");
  162.                                         }
  163.                                         catch(e){alert(e.description);}
  164.                                 }
  165.                                 this.ErrorItem[1].focus();
  166.                                 break;
  167.                         default :
  168.                                 alert(this.ErrorMessage.join("\n"));
  169.                                 break;
  170.                         }
  171.                         return false;
  172.                 }
  173.                 return true;
  174.         },
  175.         limit : function(len,min, max){
  176.                 min = min || 0;
  177.                 max = max || Number.MAX_VALUE;
  178.                 return min <= len && len <= max;
  179.         },
  180.         LenB : function(str){
  181.                 return str.replace(/[^\x00-\xff]/g,"**").length;
  182.         },
  183.         ClearState : function(elem){
  184.                 with(elem){
  185.                         if(style.color == "red")
  186.                                 style.color = "";
  187.                         var lastNode = parentNode.childNodes[parentNode.childNodes.length-1];
  188.                         if(lastNode.id == "__ErrorMessagePanel")
  189.                                 parentNode.removeChild(lastNode);
  190.                 }
  191.         },
  192.         AddError : function(index, str){
  193.                 this.ErrorItem[this.ErrorItem.length] = this.ErrorItem[0].elements[index];
  194.                 this.ErrorMessage[this.ErrorMessage.length] = this.ErrorMessage.length + ":" + str;
  195.         },
  196.         Exec : function(op, reg){
  197.                 return new RegExp(reg,"g").test(op);
  198.         },
  199.         compare : function(op1,operator,op2){
  200.                 switch (operator) {
  201.                         case "NotEqual":
  202.                                 return (op1 != op2);
  203.                         case "GreaterThan":
  204.                                 return (op1 > op2);
  205.                         case "GreaterThanEqual":
  206.                                 return (op1 >= op2);
  207.                         case "LessThan":
  208.                                 return (op1 < op2);
  209.                         case "LessThanEqual":
  210.                                 return (op1 <= op2);
  211.                         default:
  212.                                 return (op1 == op2);            
  213.                 }
  214.         },
  215.         MustChecked : function(name, min, max){
  216.                 var groups = document.getElementsByName(name);
  217.                 var hasChecked = 0;
  218.                 min = min || 1;
  219.                 max = max || groups.length;
  220.                 for(var i=groups.length-1;i>=0;i--)
  221.                         if(groups[i].checked) hasChecked++;
  222.                 return min <= hasChecked && hasChecked <= max;
  223.         },
  224.         IsDate : function(op, formatString){
  225.                 formatString = formatString || "ymd";
  226.                 var m, year, month, day;
  227.                 switch(formatString){
  228.                         case "ymd" :
  229.                                 m = op.match(new RegExp("^((\\d{4})|(\\d{2}))([-./])(\\d{1,2})\\4(\\d{1,2})$"));
  230.                                 if(m == null ) return false;
  231.                                 day = m[6];
  232.                                 month = m[5]--;
  233.                                 year =  (m[2].length == 4) ? m[2] : GetFullYear(parseInt(m[3], 10));
  234.                                 break;
  235.                         case "dmy" :
  236.                                 m = op.match(new RegExp("^(\\d{1,2})([-./])(\\d{1,2})\\2((\\d{4})|(\\d{2}))$"));
  237.                                 if(m == null ) return false;
  238.                                 day = m[1];
  239.                                 month = m[3]--;
  240.                                 year = (m[5].length == 4) ? m[5] : GetFullYear(parseInt(m[6], 10));
  241.                                 break;
  242.                         default :
  243.                                 break;
  244.                 }
  245.                 if(!parseInt(month)) return false;
  246.                 month = month==12 ?0:month;
  247.                 var date = new Date(year, month, day);
  248.         return (typeof(date) == "object" && year == date.getFullYear() && month == date.getMonth() && day == date.getDate());
  249.                 function GetFullYear(y){return ((y<30 ? "20" : "19") + y)|0;}
  250.         }
  251. }
复制代码
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播 分享分享 分享淘帖
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

网站推广
关于我们
  • 台州朗动科技(Tzweb.com)拥有多年开发网站平台系统门户手机客户端等业务的成功经验。主要从事:政企网站,系统平台,微信公众号,各类小程序,手机APP客户端,浙里办微应用,浙政钉微应用、主机域名、虚拟空间、后期维护等服务,满足不同企业公司的需求,是台州地区领先的网络技术服务商!

Hi,扫描关注我

Copyright © 2005-2026 站长论坛 All rights reserved

Powered by 站长论坛 with TZWEB Update Techonolgy Support

快速回复 返回顶部 返回列表