根据需要自行完成,参见用户注册与登录设计。
<head>
<script language="javascript" type="text/javascript">
var code ; //在全局 定义验证码
function createCode(){ //产生验证码函数
code = new Array();
var codeLength = 4;//验证码的长度
var checkCode = document.getElementById("checkCode");
checkCode.value = "";
var selectChar = new Array(2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z');
for(var i=0;i<codeLength;i++) {
var charIndex = Math.floor(Math.random()*32);
code +=selectChar[charIndex];
}
if(code.length != codeLength){
createCode();
}
checkCode.value = code;
}
}
</script>
</head>
<script language="javascript" type="text/javascript">
function validate () {//确定输入的验证码是否正确
var inputCode = document.getElementById("input1").value.toUpperCase();
if(inputCode.length <=0) {
alert("请输入验证码!"); ////验证是否输入验证码
return false;
}
else if(inputCode != code ){
alert("验证码输入错误!"); //核实验证码
createCode();
return false;
}
else {
form_submit();
return true;
}
</script>
<body onLoad="createCode();">
<div id="top"> </div>
<form id="login" name="login" action="doLogin.jsp" method="post">
<div id="center">
<div id="center_left"></div>
<div id="center_middle">
<div class="user">
<label>用户名:
<input type="text" name="username" id="username" />
</label>
</div>
<div class="user">
<label>密 码:
<input type="password" name="password" id="password" />
</label>
</div>
<div class="chknumber">
<label>验证码:
<input type="text" id="input1" />
<input type="button" id="checkCode" class="code" style="width:60px" onClick="createCode()" />
<a href="#" onClick="createCode()">看不清楚</a>
<script></script>
</div>
</div>
<div id="center_middle_right"></div>
<div id="center_submit">
<div class="button"> <img src="images/dl.gif" width="60" height="28" onclick="validate();" > </div>
<div class="button"> <img src="images/cz.gif" width="60" height="28" onclick="form_reset()"> </div>
</div>
<div id="center_right"></div>
</div>
</form>
<div id="footer"></div>
</body>