`
yhef
  • 浏览: 67069 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

JS生成验证码

 
阅读更多




<html>
	<script>
 	function createCode(){
		var tmpCode = "";
		var codeLength = 4;//验证码的长度
		var barCode = document.getElementById("barCode"); 
		barCode.innerHTML = "";		
		var selectChar = new Array('好','好','学','习','天','天','向','上');
		for(var i=0;i<codeLength;i++) {
   			var charIndex = Math.floor(Math.random()*selectChar.length);
			tmpCode +=selectChar[charIndex];
		}
		if(tmpCode.length != codeLength){
   			createCode();
		}
		barCode.innerHTML = tmpCode;
	}
	</script>
	
	<body>
		验证码:<span id="barCode" style="color:blue">Default Null</span>		
		<input type="button" onclick="createCode();"  value="Click"/> 
	</body>
</html>



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics