Generating random verification code __java with JavaScript

Source: Internet
Author: User

Note: Copy the following code to produce an effect.


<title> Untitled Page </title>
<body>
<form id= "Form1" runat= "Server" >
<div>
<div id= "Divcode" style= "background-color:white; width:52px; height:16px; padding:5px; Text-align:center; Vertical-align:middle; letter-spacing:5px; Border:solid 1px Blue "><span></span><span ></span><span ></span><span ></span></div>
</div>
<input id= "Button1" type= "button" value= "for another" onclick= "Javascript:validtecode ()"/>
</form>
</body>
<script language= "JavaScript" type= "Text/javascript" >
function Validtecode ()
{
var codes = new Array (4); For storing random authentication codes
var colors = new Array ("Red", "Green", "Gray", "Blue", "maroon", "Aqua", "Fuchsia", "Lime", "Olive", "Silver");
for (Var i=0;i < codes.length;i++)
{//Get random Authentication Code
Codes[i] = Math.floor (Math.random () *10);
}
var spans = document.getElementById ("Divcode"). All;
for (Var i=0;i<spans.length;i++)
{
Spans[i].innerhtml=codes[i];
Spans[i].style.color = Colors[math.floor (Math.random () *10)]; Randomly set Authenticode color

}

}
Document.onload = Validtecode ();
</script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.