例:以下:
次のようにコードコードをコピーします。
<
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<メタhttp-equiv = "content-type" content = "text /html; charset = gb2312" /> />
<title> js検証コード</title>
<style type = "text/css">
。コード
{{
背景画像:url(code.jpg);
フォントファミリー:arial;
フォントスタイル:イタリック;
色:赤;
ボーダー:0;
パディング:2px 3px;
レター間隔:3px;
font-weight:Bolder;
}
.unchanged
{{
ボーダー:0;
}
</style>
<スクリプト言語= "javascript" type = "text/javascript">
varコード
functionCreateCode()
{{
code = "";
var codengent = 4; //検証コードの長さ
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' '' '' '' '' '、' k '、' l '、' m '、' n '、' o '、' p '、' q '、' r '、' s 、 's、' t '、' u '、' v '、' ww '、' x '、' y '、' z ');中国語で中国語を使用することもできます
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値()
{{
var inputCode = document.getElementByID( "input1")。
if(inputCode.length <= 0)
{{
alert( "検証コードを入力してください!");
}
else if(inputCode!= code)
{{
alert( "検証コード入力エラー!");
CreateCode(); //検証コードを更新します
}
それ以外
{{
アラート( "ok");
}
}
</script>
</head>
<bodyのみ= "createcode()" >>
<form action = "#">
<input type = "text" id = "input1" />
<入力型= "text" onclick = "createcode()" readonly = "readonly" id = "checkcode" /> <br />
<入力id = "button1" onclick = "validate();" button "value =" ok " /> /> />
</form>
</body>
</html>