久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      javascript如何制作驗證碼

      javascript制作驗證碼的方法:【var code; window.onload = function creatCode() { code=""; var codeLength = 4; var checkCode = …}】。

      javascript如何制作驗證碼

      本文操作環(huán)境:windows10系統(tǒng)、javascript 1.8.5、thinkpad t480電腦。

      使用javascript實現(xiàn)登錄驗證碼功能,下面是具體的實現(xiàn)代碼:

      test.html

      <!DOCTYPE html> <html>   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <head>   	<title>驗證碼</title>    	<script src = "checkCode.js">   </script>   </head>   <body>   	<div>   		<input type = "text" id = "input"/>   		<input type = "button" id="code" οnclick="createCode()"/>   		<input type = "button" value = "驗證" onclick = "validate()"/>   	</div>   </body>  </html>

      checkCode.js

      var code ; //在全局定義驗證碼      window.onload = function createCode(){   	 code = "";    	 var codeLength = 4;//驗證碼的長度   	 var checkCode = document.getElementById("code");    	 var random = new Array(0,1,2,3,4,5,6,7,8,9,'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');//隨機數(shù)   	 for(var i = 0; i < codeLength; i++) {//循環(huán)操作   		var index = Math.floor(Math.random()*36);//取得隨機數(shù)的索引(0~35)   		code += random[index];//根據(jù)索引取得隨機數(shù)加到code上   	}   	checkCode.value = code;//把code值賦給驗證碼   }   //校驗驗證碼   function validate(){   	var inputCode = document.getElementById("input").value.toUpperCase(); //取得輸入的驗證碼并轉(zhuǎn)化為大寫         	if(inputCode.length <= 0) { //若輸入的驗證碼長度為0   		alert("Empty Code!"); //則彈出請輸入驗證碼   	}          	else if(inputCode != code ) { //若輸入的驗證碼與產(chǎn)生的驗證碼不一致時   		alert("Error Code"); //則彈出驗證碼輸入錯誤   		createCode();//刷新驗證碼   		document.getElementById("input").value = "";//清空文本框   	}          	else { //輸入正確時   		alert("OK"); //彈出^-^   	}              }

      點擊的時候不會移動位置的代碼:

      <p class="red"><a href="javascript:;" οnclick="createCode()">看不清?</a></p>

      推薦學習:javascript視頻教程

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號