JSP新增非空验证

add.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>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("");
		}
	})
})

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值