前台页面:、
<%@ 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>Insert title here</title>
<script type="text/javascript" src="js/jquery-2.1.0.js" ></script>
<script type="text/javascript" src="js/add.js" ></script>
</head>
<body>
<h1>添加用户</h1>
<form action="add" method="post">
用户名:<input type="text" name="sacc" id="sacc"><span id="tsacc" style="color: red"></span><br>
密码:<input type="text" name="spwd" id="spwd"><span id="tspwd" style="color: red"></span><br>
真实姓名:<input type="text" name="sname" id="sname"><span id="tsname" style="color: red"></span><br>
地址:<input type="text" name="address" id="address"><span id="tsaddress" style="color: red"></span><br>
电话:<input type="text" name="phone" id="phone"><span id="tsphone" style="color: red"></span><br>
<button type="submit">添加</button>
</form>
</body>
</html>
js页面:
$().ready(function(){
$("#sacc").on('focusout',function(){
if($("#sacc").val()==''){
$("#tsacc").text("用户名不能为空");
}else{
$("#tsacc").text("");
}
})
$("#spwd").on('focusout',function(){
if($("#spwd").val()==''){
$("#tspwd").text("密码不能为空");
}else{
$("#tspwd").text("");
}
})
$("#sname").on('focusout',function(){
if($("#sname").val()==''){
$("#tsname").text("真实姓名不能为空");
}else{
$("#tsname").text("");
}
})
$("#address").on('focusout',function(){
if($("#address").val()==''){
$("#tsaddress").text("地址不能为空");
}else{
$("#tsaddress").text("");
}
})
$("#phone").on('focusout',function(){
if($("#phone").val()==''){
$("#tsphone").text("电话不能为空");
}else{
$("#tsphone").text("");
}
})
})