高仿“点触验证码”做的一个静态Html例子

来源:互联网 发布:阿里云系统看电视 编辑:程序博客网 时间:2024/06/06 09:50

先上源码:

[html] view plain copy
 print?
  1. <html>  
  2. <head>  
  3.     <title>TouClick - Designed By MrChu</title>  
  4.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
  5.     <style type="text/css">  
  6.         body {  
  7.             margin: 0px;  
  8.             padding: 0px;  
  9.         }  
  10.   
  11.         .click_area {  
  12.             height: 320px;  
  13.             text-align: center;  
  14.             background: #777777;  
  15.         }  
  16.   
  17.         #season {  
  18.             border: none;  
  19.         }  
  20.   
  21.         .keywords {  
  22.             color: #FF0000;  
  23.         }  
  24.     </style>  
  25.     <script type="text/javascript">  
  26.         var touch = 1;  
  27.         var spring = 0;  
  28.         var summer = 0;  
  29.         var autumn = 0;  
  30.         var winter = 0;  
  31.         var first = false;  
  32.         var second = false;  
  33.         function changeStyle () {  
  34.             if (touch < 4) {  
  35.                 touch++;  
  36.             } else {  
  37.                 touch = 1;  
  38.             }  
  39.             spring = 0;  
  40.             summer = 0;  
  41.             autumn = 0;  
  42.             winter = 0;  
  43.             first = false;  
  44.             second = false;  
  45.             $("txt1").style.color = "#FF0000";  
  46.             $("txt2").style.color = "#FF0000";  
  47.             // Spring  
  48.             if (touch == 1) {  
  49.                 $("season").src = "images/spring.jpg";  
  50.                 $("season").useMap = "#springMap";  
  51.                 $("txt1").innerText = "春";  
  52.                 $("txt2").innerText = "桃";  
  53.             }  
  54.             // Summer  
  55.             if (touch == 2) {  
  56.                 $("season").src = "images/summer.jpg";  
  57.                 $("season").useMap = "#summerMap";  
  58.                 $("txt1").innerText = "夏";  
  59.                 $("txt2").innerText = "荷";  
  60.             }  
  61.             // Autumn  
  62.             if (touch == 3) {  
  63.                 $("season").src = "images/autumn.jpg";  
  64.                 $("season").useMap = "#autumnMap";  
  65.                 $("txt1").innerText = "秋";  
  66.                 $("txt2").innerText = "菊";  
  67.             }  
  68.             // Winter  
  69.             if (touch == 4) {  
  70.                 $("season").src = "images/winter.jpg";  
  71.                 $("season").useMap = "#winterMap";  
  72.                 $("txt1").innerText = "冬";  
  73.                 $("txt2").innerText = "梅";  
  74.             }  
  75.         }  
  76.   
  77.         // Spring  
  78.         function springClick (txt) {  
  79.             if (spring == 0) {  
  80.                 if (txt == "春") {  
  81.                     first = true;  
  82.                     $("txt1").style.color = "#008040";  
  83.                 }  
  84.             }  
  85.             if (spring == 1) {  
  86.                 if (txt == "桃") {  
  87.                     second = true;  
  88.                     $("txt2").style.color = "#008040";  
  89.                 }  
  90.             }  
  91.             if (spring >= 1) {  
  92.                 if (first && second) {  
  93.                     alert("验证成功!");  
  94.                     changeStyle();  
  95.                 } else {  
  96.                     alert("验证失败!");  
  97.                     changeStyle();  
  98.                 }  
  99.             }  
  100.             spring++;  
  101.         }  
  102.   
  103.         // Summer  
  104.         function summerClick (txt) {  
  105.             if (summer == 0) {  
  106.                 if (txt == "夏") {  
  107.                     first = true;  
  108.                     $("txt1").style.color = "#008040";  
  109.                 }  
  110.             }  
  111.             if (summer == 1) {  
  112.                 if (txt == "荷") {  
  113.                     second = true;  
  114.                     $("txt2").style.color = "#008040";  
  115.                 }  
  116.             }  
  117.             if (summer >= 1) {  
  118.                 if (first && second) {  
  119.                     alert("验证成功!");  
  120.                     changeStyle();  
  121.                 } else {  
  122.                     alert("验证失败!");  
  123.                     changeStyle();  
  124.                 }  
  125.             }  
  126.             summer++;  
  127.         }  
  128.   
  129.         // Autumn  
  130.         function autumnClick (txt) {  
  131.             if (autumn == 0) {  
  132.                 if (txt == "秋") {  
  133.                     first = true;  
  134.                     $("txt1").style.color = "#008040";  
  135.                 }  
  136.             }  
  137.             if (autumn == 1) {  
  138.                 if (txt == "菊") {  
  139.                     second = true;  
  140.                     $("txt2").style.color = "#008040";  
  141.                 }  
  142.             }  
  143.             if (autumn >= 1) {  
  144.                 if (first && second) {  
  145.                     alert("验证成功!");  
  146.                     changeStyle();  
  147.                 } else {  
  148.                     alert("验证失败!");  
  149.                     changeStyle();  
  150.                 }  
  151.             }  
  152.             autumn++;  
  153.         }  
  154.   
  155.         // Winter  
  156.         function winterClick (txt) {  
  157.             if (winter == 0) {  
  158.                 if (txt == "冬") {  
  159.                     first = true;  
  160.                     $("txt1").style.color = "#008040";  
  161.                 }  
  162.             }  
  163.             if (winter == 1) {  
  164.                 if (txt == "梅") {  
  165.                     second = true;  
  166.                     $("txt2").style.color = "#008040";  
  167.                 }  
  168.             }  
  169.             if (winter >= 1) {  
  170.                 if (first && second) {  
  171.                     alert("验证成功!");  
  172.                     changeStyle();  
  173.                 } else {  
  174.                     alert("验证失败!");  
  175.                     changeStyle();  
  176.                 }  
  177.             }  
  178.             winter++;  
  179.         }  
  180.           
  181.         // 图片抖动脚本  
  182.         var typ = ["marginTop", "marginLeft"], rangeN=10timeout=20;  
  183.         function shake(o, end){  
  184.             var range = Math.floor(Math.random() * rangeN);  
  185.             var typN = Math.floor(Math.random() * typ.length);  
  186.             o["style"][typ[typN]] = "" + range + "px";  
  187.             var shakeTimer = setTimeout(function(){shake(o, end)}, timeout);  
  188.             o[end] = function(){  
  189.                 clearTimeout(shakeTimer)  
  190.             };  
  191.         }  
  192.   
  193.         function $(id){  
  194.             return document.getElementById(id);  
  195.         }  
  196.     </script>  
  197. </head>  
  198. <body>  
  199.     <div class="click_area">  
  200.         <center>  
  201.             <div id="tb_clothes" onClick="shake(this, 'onmouseout')" style="width:372px;height:303px;background:#B7BBC3;">  
  202.                 <table width="372" height="303" border="0" cellpadding="0" cellspacing="0">  
  203.                     <tr>  
  204.                         <td colspan="5">  
  205.                             <img src="images/TouClick_01.jpg" width="372" height="7" alt=""></td>  
  206.                     </tr>  
  207.                     <tr>  
  208.                         <td rowspan="2">  
  209.                             <img src="images/TouClick_02.jpg" width="7" height="197" alt=""></td>  
  210.                         <td colspan="3">  
  211.                             <img src="images/spring.jpg" width="358" height="181" id="season" useMap="#springMap"></td>  
  212.                         <td rowspan="2">  
  213.                             <img src="images/TouClick_04.jpg" width="7" height="197" alt=""></td>  
  214.                     </tr>  
  215.                     <tr>  
  216.                         <td colspan="3">  
  217.                             <img src="images/TouClick_05.jpg" width="358" height="16" alt=""></td>  
  218.                     </tr>  
  219.                     <tr>  
  220.                         <td colspan="5">  
  221.                             <div style="width:372;height:26;font-family:'微软雅黑';font-size:16px;text-align:center;background:#F5F6F8;border:none;">点触验证:请依次点击图片中的"<span id="txt1" class="keywords"></span>","<span id="txt2" class="keywords"></span>"</div>  
  222.                         </td>  
  223.                     </tr>  
  224.                     <tr>  
  225.                         <td colspan="5">  
  226.                             <img src="images/TouClick_07.jpg" width="372" height="17" alt=""></td>  
  227.                     </tr>  
  228.                     <tr>  
  229.                         <td colspan="2" rowspan="2">  
  230.                             <img src="images/TouClick_08.jpg" width="167" height="55" alt=""></td>  
  231.                         <td>  
  232.                             <img src="images/TouClick_09.jpg" width="37" height="37" onClick="changeStyle();" onMouseDown="this.src='images/TouClick_Active.jpg'" onMouseUp="this.src='images/TouClick_09.jpg'" style="cursor:pointer;"></td>  
  233.                         <td colspan="2" rowspan="2">  
  234.                             <img src="images/TouClick_10.jpg" width="168" height="55" alt=""></td>  
  235.                     </tr>  
  236.                     <tr>  
  237.                         <td>  
  238.                             <img src="images/TouClick_11.jpg" width="37" height="18" alt=""></td>  
  239.                     </tr>  
  240.                     <tr>  
  241.                         <td>  
  242.                             <img src="images/分隔符.gif" width="7" height="1" alt=""></td>  
  243.                         <td>  
  244.                             <img src="images/分隔符.gif" width="160" height="1" alt=""></td>  
  245.                         <td>  
  246.                             <img src="images/分隔符.gif" width="37" height="1" alt=""></td>  
  247.                         <td>  
  248.                             <img src="images/分隔符.gif" width="161" height="1" alt=""></td>  
  249.                         <td>  
  250.                             <img src="images/分隔符.gif" width="7" height="1" alt=""></td>  
  251.                     </tr>  
  252.                 </table>  
  253.             </div>  
  254.         </center>  
  255.     </div>  
  256.     <map name="springMap">  
  257.         <area shape="circle" coords="64,133,17" href="javascript:springClick('春');" onfocus="this.blur()">  
  258.         <area shape="circle" coords="268,151,18" href="javascript:springClick('桃');" onfocus="this.blur()">  
  259.     </map>  
  260.     <map name="summerMap">  
  261.         <area shape="circle" coords="303,42,20" href="javascript:summerClick('夏');" onfocus="this.blur()">  
  262.         <area shape="circle" coords="233,149,17" href="javascript:summerClick('荷');" onfocus="this.blur()">  
  263.     </map>  
  264.     <map name="autumnMap">  
  265.         <area shape="circle" coords="211,74,19" href="javascript:autumnClick('秋');" onfocus="this.blur()">  
  266.         <area shape="circle" coords="46,49,18" href="javascript:autumnClick('菊');" onfocus="this.blur()">  
  267.     </map>  
  268.     <map name="winterMap">  
  269.         <area shape="circle" coords="108,158,18" href="javascript:winterClick('冬');" onfocus="this.blur()">  
  270.         <area shape="circle" coords="245,91,19" href="javascript:winterClick('梅');" onfocus="this.blur()">  
  271.     </map>  
  272. </body>  
  273. </html>  

效果图:

1、验证界面

2、可点击区域

3、点击之后

4、验证成功

5、验证失败

6、点击切换验证图片

7、切换成功

8、demo下载

高仿“点触验证码”做的一个静态Html例子:http://download.csdn.net/detail/for_china2012/6339655

0 0
原创粉丝点击