2015-01-15 114 views
-2

可以幫我打印上新的HTML頁面captcah 我媒體鏈接到我的javascrip.js鏈接到我的index.html斜面打印Captcah陣列

function autoCaptcah() // munculkan Captcah 
{ 
     var temp1 = new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'); 
     var temp2 = new Array('1','2','3','4','5','6','7','8','9','0'); 

    //do looping for the captcah 
    for(var i = 0; i<5; i++) 
    { 
     var huruf1 = temp1[Math.floor(Math.random()*temp1.length)]; 
     var huruf2 = temp1[Math.floor(Math.random()*temp1.length)]; 
     var angka1 = temp2[Math.floor(Math.random()*temp2.length)]; 
     var angka2 = temp2[Math.floor(Math.random()*temp2.length)]; 
     var angka3 = temp2[Math.floor(Math.random()*temp2.length)]; 
     var captcah = huruf1+huruf2+angka1+angka2+angka3; 
     document.getElementById("commandCaptcah").value = captcah; 
    } 


} 

回答

0
<html> 
    <script> 
     function autoCaptcah() // munculkan Captcah 
     { 

      var temp1 = new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'); 
      var temp2 = new Array('1','2','3','4','5','6','7','8','9','0'); 

      //do looping for the captcah 
      for(var i = 0; i<5; i++) 
      { 
       var huruf1 = temp1[Math.floor(Math.random()*temp1.length)]; 
       var huruf2 = temp1[Math.floor(Math.random()*temp1.length)]; 
       var angka1 = temp2[Math.floor(Math.random()*temp2.length)]; 
       var angka2 = temp2[Math.floor(Math.random()*temp2.length)]; 
       var angka3 = temp2[Math.floor(Math.random()*temp2.length)]; 
       var captcah = huruf1+huruf2+angka1+angka2+angka3; 
       document.getElementById("commandCaptcah"+i).innerHTML = captcah; 
      } 

     } 
    </script> 
    <body> 
     <div> 
     <span id="commandCaptcah0"></span><br> 
     <span id="commandCaptcah1"></span><br> 
     <span id="commandCaptcah2"></span><br> 
     <span id="commandCaptcah3"></span><br> 
     <span id="commandCaptcah4"></span><br> 
     <input type="submit" onclick="javascript:autoCaptcah()"/> 
     </div> 

    </body> 
</html> 

我希望幫助你

0
<html> 
     <head> 
      <script type="text/javascript"> 
       function Captcha(){ 
        var temp1 = new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'); 
        var temp2 = new Array('1','2','3','4','5','6','7','8','9','0'); 
        var i; 
        for (i=0;i<6;i++){ 
         var a = temp1[Math.floor(Math.random() * temp1.length)]; 
         var b = temp1[Math.floor(Math.random() * temp1.length)]; 
         var c = temp2[Math.floor(Math.random() * temp2.length)]; 
         var d = temp2[Math.floor(Math.random() * temp2.length)]; 
         var e = temp2[Math.floor(Math.random() * temp2.length)]; 
         } 
        var code = a + b + c + d + e ; 
        document.getElementById("mainCaptcha").value = code 
        } 
        function ValidCaptcha(){ 
         var string1 = removeSpaces(document.getElementById('mainCaptcha').value); 
         var string2 = removeSpaces(document.getElementById('txtInput').value); 
         if (string1 == string2){ 
         return true; 
         } 
         else{   
         return false; 
         } 
        } 
        function removeSpaces(string){ 
        return string.split(' ').join(''); 
        } 
      </script>  
     </head> 
    <body onload="Captcha();"> 
     <table> 
      <tr> 
      <td> 
       Text Captcha<br /> 
      </td> 
      </tr> 
      <tr> 
      <td> 
      <input type="text" id="mainCaptcha"/> 
       <input type="button" id="refresh" value="Refresh" onclick="Captcha();" /> 
      </td> 
      </tr> 
      <tr> 
      <td> 
      <input type="text" id="txtInput"/>  
      </td> 
     </tr> 
     <tr> 
      <td> 
      <input id="Button1" type="button" value="Check" onclick="alert(ValidCaptcha());"/> 
      </td> 
     </tr> 
     </table> 
    </body> 
</html>