Examples as: below:
Copy code code as follows:
<! Doctype HTML PUBLIC "-// W3C // DTD XHTML 1.0 Transitional // EN" http://www.w3.org/xhtml1/dtddml1-transitationAl.dtd ">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "content-type" content = "text /html; charset = gb2312" /> />
<Title> JS Verification Code </Title>
<Style Type = "Text/CSS">
.code
{{
background-image: url (code.jpg);
FONT-FAMILY: Arial;
FONT-Style: Italic;
color: red;
border: 0;
padding: 2px 3px;
Letter-spacing: 3px;
FONT-Weight: Bolder;
}
.unchangeded
{{
border: 0;
}
</style>
<script language = "javascript" type = "text/javascript">
var code; // Define the verification code in the global definition
Function Createcode ()
{{
code = "";
Var codength = 4; // The length of the verification code
var checkCode = document.GetelementByid ("CheckCode");
var selectChar = 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,' s, 's 't', 'u', 'v', 'ww', 'x', 'y', 'z'); // All candidates form the characters of the verification code, of course, you can also use Chinese in Chinese
for (var I = 0; I <codength; i ++)
{{
var charindex = math.floor (math.random ()*36);
code += selectchar [charindex];
}
// alert (code);
if (CheckCode)
{{
CheckCode.classname = "Code";
CheckCode.value = code;
}
}
Function value ()
{{
var inputCode = document.GetelementByid ("input1"). Value;
if (InputCode.length <= 0)
{{
alert ("Please enter the verification code!");
}
else if (inputCode! = Code)
{{
alert ("Verification code input error!");
createCode (); // Refresh the verification code
}
else
{{
alert ("ok");
}
}
</script>
</head>
<body only = "createcode ()">>
<form action = "#">
<input type = "text" id = "input1" />
<input type = "text" onClick = "Createcode ()" Readonly = "Readonly" ID = "CheckCode" /> <br />
<input ID = "Button1" Onclick = "Validate ();" Type = "Button" Value = "OK" /> /> />
</form>
</body>
</html>