ตัวอย่างเป็น: ด้านล่าง:
คัดลอกรหัสรหัสดังนี้:
<!
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "content-type" content = "text /html; charset = gb2312" /> />
<title> รหัสตรวจสอบ JS </title>
<style type = "text/css">
.รหัส
-
ภาพพื้นหลัง-ภาพ: url (code.jpg);
Font-Family: Arial;
แบบฟอนต์: ตัวเอียง;
สี: สีแดง;
ชายแดน: 0;
Padding: 2px 3px;
ระยะห่างจดหมาย: 3px;
Font-Weight: Bolder;
-
. เปิดตัว
-
ชายแดน: 0;
-
</style>
<script language = "javascript" type = "text/javascript">
รหัส VAR;
ฟังก์ชั่น createCode ()
-
รหัส = "";
var codnength = 4;
var checkCode = document.getElementById ("CheckCode");
var selectchar = อาร์เรย์ใหม่ (0,1,2,3,4,5,6,7,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'); คุณยังสามารถใช้ภาษาจีนเป็นภาษาจีนได้
สำหรับ (var i = 0; i <codength; i ++)
-
var charindex = math.floor (math.random ()*36);
รหัส += selectchar [charindex];
-
// Alert (รหัส);
ถ้า (CheckCode)
-
checkCode.className = "รหัส";
checkCode.Value = รหัส;
-
-
ค่าฟังก์ชัน ()
-
var inputcode = document.getElementById ("input1")
if (inputCode.Length <= 0)
-
การแจ้งเตือน ("โปรดป้อนรหัสการยืนยัน!");
-
อื่นถ้า (inputcode! = code)
-
การแจ้งเตือน ("ข้อผิดพลาดอินพุตรหัสการยืนยัน!");
createCode ();
-
อื่น
-
การแจ้งเตือน ("ตกลง");
-
-
</script>
</head>
<body only = "createCode ()" >>
<form action = "#">
<อินพุต type = "text" id = "input1" />
<อินพุต type = "text" onclick = "createCode ()" readonly = "readonly" id = "checkCode" /> <br />
<อินพุต id = "button1" onclick = "ตรวจสอบ ();" type = "button" value = "ตกลง" /> /> />
</form>
</body>
</html>