核心: document.getElementById("formid").submit();
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>登陆界面</title>
<link rel="stylesheet" href="index.css">
<style>
*{
margin: 0;
padding: 0;
list-style: none;
}
body{
width:100%;
background-image: url('img/bg.jpg');
background-size: cover;
}
.main{
width:40%;
margin-left:30%;
margin-right:30%;
margin-top:200px;
}
.header{
margin-top:100px;
height:100px;
text-align:center;
font-size:60px;
font-family: 华文新魏;
color: #dacc3e;
}
.headline{
font-size: 22px;
text-align: center;
color: #fffefd;
}
input[type="text"],
input[type="password"],
input[type="button"]{
-web-kit-appearance:none;
-moz-appearance: none;
display: block;
margin: 0 auto;
font-size:15px;
width: 35%;
}
input[type="text"],
input[type="password"]{
height:36px;
border-radius:18px;
border:1px solid #c8cccf;
color:#6a6f77;
outline:0;
}
input[type="button"]{
margin-top: 25px;
height: 35px;
background: #357eb8;
color: #bcedff;
font-weight: bold;
font-size: 16px;
border-radius:18px;
}
input[type="button"]:hover{
background: #0e62a3;
cursor: pointer;
}
.astyle{
margin-left:35%;
margin-right:35%;
font-size:17px;
color: #6a6f77;
}
.astyle{
color:#fff5d3;
margin-top: 20px;
}
.isLogin{
text-align: center;
color: red;
}
</style>
</head>
<body>
<div class="container">
<div class="header">红星医院后台管理系统</div>
<!-- 主体内容 (登陆界面)--><div class="main">
<form:form id="formid" action="adminlogin" modelAttribute="admin" method="post">
<p class="headline"><strong>超级管理员登陆</strong></p>
<p class="astyle">用户账号:</p>
<form:input type="text" id="id" placeholder="请输入账号" path="id" />
<p class="astyle">密码:</p>
<form:input type="password" id="adminpassword" placeholder="请输入密码" path="adminpassword" />
<input type="button" value="登陆" name="login" onclick="adminsubmit();"><br>
<c:if test="${loginflag}">
<p class="isLogin">密码或账号错误</p>
</c:if>
</form:form>
</div>
</div>
<script type="text/javascript">
function adminsubmit()
{
//获取用户账号
var account=document.getElementById("id").value;
//alert(account);
//获取用户密码
var password=document.getElementById("adminpassword").value;
//提交标志
var flag=true;
//正则表达式
var reg=new RegExp("^([1-9][0-9]*)$");
//验证账户不为空
if(account.toString()=="")
{
alert(100);
flag=false;
alert("对不起!账号不能为空");
}else
{ //验证不为0开头并且不含有其他字符
if(!reg.test(account)){
flag=false;
alert("对不起! 账号起始不能为0");
}else{
//验证密码不能为空
if(password=="")
{
flag=false;
alert("对不起!密码不能为空,并且不含有其他非数字字符");
}
}
}
//判断是否提交
if(flag==true)
{
document.getElementById("formid").submit();
}
}
</script>
</body>
</html>