简单学生选课系统之登录界面

时间:2021-09-26 15:32:21

图片

简单学生选课系统之登录界面

代码:

checkcode.jsp

var code ; //在全局定义验证码   
//产生验证码
function createCode(){
code = "";
var codeLength = 4;//验证码的长度
var checkCode = document.getElementById("checkCode");
var random = new Array(0,1,2,3,4,5,6,7,8,9,'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');//随机数
for(var i = 0; i < codeLength; i++) {//循环操作
var index = Math.floor(Math.random()*36);//取得随机数的索引(0~35)
code += random[index];//根据索引取得随机数加到code上
//把code值赋给验证码
if (checkCode) {
checkCode.className = "code";
checkCode.value = code;
checkCode.blur();
}
}
}
function validate(){
var inputCode = document.getElementById("test").value;
if (inputCode.length <= 0) {
alert("请输入验证码!");
return false;
} else if (inputCode.toUpperCase() != code) {
alert("验证码输入错误!");
createCode();// 刷新验证码
return false;
}
register.submit();
}
test.js 

function check(register){
var no=register.studentno.value;
var pass=register.password.value;
var tests=register.test.value;
if(no==""){
alert("学号不能为空!");
register.studentno.focus();
register.studentno.select();
}
else if(pass==""){
alert("密码不能为空!");
register.password.focus();
register.password.select();
}
else if(tests==""){
alert("验证码不能为空!");
register.test.focus();
register.test.select();
}
else if(type==""){
alert("类型不能为空!");
}
return true;
}
date.js

var time,year,month,day,hour,minute,second;
var today=new Date();
month=today.getMonth()+1;
day=today.getDay();
var s=today.getFullYear()+"年"+month+"月"+today.getDate()+"日"+today.getHours()+"时"+today.getMinutes()+"分"+today.getSeconds()+"秒"+"\t";
document.write(s);
switch(day){
case 1:document.write("星期一");break;
case 2:document.write("星期二");break;
case 3:document.write("星期三");break;
case 4:document.write("星期四");break;
case 5:document.write("星期五");break;
case 6:document.write("星期六");break;
case 7:document.write("星期日");break;
}
firstpage.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>学生选课系统</title>
<style type="text/css">
body{margin:0}
.whole{
width:1520px;
height:800px;
background:url(timg.jpg);

}
.head{
height:300px;
width:1520px;
}
.lhead{
float:right;
}
.main{
width:1520px;
height:500px;
}
</style>
<script type="text/javascript" src="checkcode.js"></script>
<script type="text/javascript" src="test.js"></script>
</head>
<body>
<div class="whole">
<div class="head">
<div class="lhead">
<script type="text/javascript" src="date.js"></script>
</div>
<h style="font-size:60px;color:#ffff00"><marquee behavior="alternate";scrolldelay="10";>欢迎进入选课系统</marquee></h>
</div>
<div class="main">
<center>
<form action="dofirstpage.jsp" name="register" method="post" onClick="return check(this)">
  学 号:<input type="text" name="studentno" value=""><br>
  密 码:<input type="password" name="password" value=""><br>
  验证码:<input type="text" id="test" style="width:90px">
<input type="text" onClick="createCode();" readonly="readonly" id="checkCode" class="unchanged" style="width: 56px;cursor:pointer" />
<br>
类 型:
<input type="radio" name="types" value="学生">学生
<input type="radio" name="types" value="管理员">管理员<br>
  <input type="submit" value="登录" onClick="validate();">
<input type="reset" value="重置">
</form>
</center>
</div>
</div>
</body>
</html>