<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>
JS生成验证码
最新推荐文章于 2022-12-07 11:32:10 发布