The effect is as follows: Copy code The code is as follows: <br> .code<br> {<br> background:url(code_bg.jpg);<br> font-family:Arial;<br> font-style:italic;<br> color:blue;<br> font-size:30px;<br> border:0;<br> padding:2px 3px;<br> letter-spacing:3px;<br> font-weight:bolder; <br> float:left; <br> cursor:pointer;<br> width:150px;<br> height:60px;<br> line-height:60px;<br> text-align:center;<br> vertical-align:middle;<br><br> }<br> a<br> {<br> text-decoration:none;<br> font-size:12px;<br> color:#288bc4;<br> }<br> a:hover<br> {<br> text-decoration:underline;<br> }<br> <br><br> var code;<br> function createCode() {<br> code = "";<br> var codeLength = 6; //验证码的长度<br> var checkCode = document.getElementById("checkCode");<br> var codeChars = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, <br> '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',<br> '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'); //所有候选组成验证码的字符,当然也可以用中文的<br> for (var i = 0; i < codeLength; i ) <BR> {<BR> var charNum = Math.floor(Math.random() * 52);<BR> code = codeChars[charNum];<BR> }<BR> if (checkCode) <BR> {<BR> checkCode.className = "code";<BR> checkCode.innerHTML = code;<BR> }<BR> }<BR> function validateCode() <BR> {<BR> var inputCode = document.getElementById("inputCode").value;<BR> if (inputCode.length <= 0) <BR> {<BR> alert( "Please enter the verification code!"); <BR>} <BR> Else if (inputCode.touppercase ()! = Code.touppercase ()) <BR> {<BR> Alert ("The verification code is input error!") ;<BR> createCode();<BR> }<BR> else <BR> {<BR> alert("Verification code is correct!");<BR> 🎜><BR></head><br><body onload="createCode()"><br> <form id="form1" runat="server" onsubmit="validateCode()"> <br> ;td> <div class="code" id="checkCode" onclick="createCode()" ></div></td><br> onclick="createCode()">If you can’t see clearly, change another one</a></td><br> </td><td><input style="float:left;" type="text" id="inputCode" /></td><td>Please enter the verification code</td> ;<BR> value="OK" /></td><td></td><br> ;/form><br></body><br></html><br> <br><br><br></p> </div>