1. 程式人生 > >學齋隨筆,初九潛龍勿用,-16驗證碼

學齋隨筆,初九潛龍勿用,-16驗證碼

 1 <!doctype html>
 2 <html>
 3 <head>
 4 <meta charset="utf-8">
 5 <title>驗證碼</title>
 6 </head>
 7 
 8 <body>
 9 請輸入驗證碼:
10     <span id="yzm1" style="background: #ccc"></span><br>
11     <input type="text" id="yzm">
12     <button 
id="btn">驗證是否正確</button> 13 </body> 14 </html> 15 <script> 16 var yzm = document.getElementById("yzm"); 17 var yzm1=document.getElementById("yzm1"); 18 var btn =document.getElementById("btn"); 19 20 getYzm(); 21 yzm1.onclick = getYzm; 22 btn.onclick = function(){ 23 var
zhi1=yzm.value; 24 var zhi2=yzm1.innerHTML; 25 if(zhi1==zhi2){ 26 alert("正確,眼神不錯"); 27 }else{ 28 alert("驗證碼錯誤,你好好瞅瞅"); 29 } 30 } 31 32 33 34 function getYzm(){ 35 var str = "123456789abcdefg"; 36 str = str.split(""); 37 var zhi = ""; 38 for(var i =0;i
<4;i++){ 39 zhi += str[parseInt(Math.random()*str.length)]; 40 } 41 yzm1.innerHTML = zhi; 42 } 43 44 45 </script>