JavaScript code generation

Source: Internet
Author: User
Code:
  1. <PRE name = "code" class = "JS"> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <HTML xmlns = "http://www.w3.org/1999/xhtml">
  3. <Head>
  4. <Title> No title page </title>
  5. <Style type = "text/CSS">
  6. . Code
  7. {
  8. Background-image: url(code.jpg );
  9. Font-family: Arial;
  10. Font-style: italic;
  11. Color: red;
  12. Border: 0;
  13. Padding: 2px 3px;
  14. Letter-Spacing: 3px;
  15. Font-weight: bolder;
  16. }
  17. . Unchanged
  18. {
  19. Border: 0;
  20. }
  21. </Style>
  22. <Script language = "javascript" type = "text/javascript">
  23. Var code; // define the verification code globally
  24. Function createCode ()
  25. {
  26. Code = "";
  27. VaR codelength = 4; // The length of the Verification Code
  28. VaR checkcode = Document. getelementbyid ("checkcode ");
  29. VaR selectchar = new array (, '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'); // all the characters whose candidates constitute the verification code. Of course, they can also be in Chinese.
  30. For (VAR I = 0; I <codelength; I ++)
  31. {
  32. Var charIndex = Math. floor (Math. random () * 36 );
  33. Code + = selectChar [charIndex];
  34. }
  35. // Alert (code );
  36. If (checkCode)
  37. {
  38. CheckCode. className = "code ";
  39. CheckCode. value = code;
  40. }
  41. }
  42. Function validate ()
  43. {
  44. Var inputCode = document. getElementById ("input1"). value;
  45. If (inputCode. length <= 0)
  46. {
  47. Alert ("Enter the verification code! ");
  48. }
  49. Else if (inputcode! = Code)
  50. {
  51. Alert ("Incorrect verification code! ");
  52. Createcode (); // refresh the verification code
  53. }
  54. Else
  55. {
  56. Alert ("^-^ OK ");
  57. }
  58. }
  59. </Script>
  60. </Head>
  61. <Body onload = "createCode ()">
  62. <Form action = "#">
  63. <Input type = "text" id = "input1"/>
  64. <Input type = "text" onclick = "createcode ()" readonly = "readonly" id = "checkcode" class = "unchanged" style = "width: 80px "/> <br/>
  65. <Input id = "button1" onclick = "Validate ();" type = "button" value = "OK"/>
  66. </Form>
  67. </Body>
  68. </Html> </PRE>

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.