<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Jquery实现表单验证</title>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
</head>
<body>
<form action="#" method="post" align="center" id="addUser">
<label for="username">用户名:</label>
<input type="text" name="username" id="username">
<br/>
<label for="password">密码:</label>
<input type="password" name="password">
<br/>
<input type="submit" name="登录">
</form>
<script>
$('#addUser').submit(function(){
if($("#username").val() =='' || $("#password").val() == ''){
alert("请输入完整信息!");
return false;
}
})
</script>
</body>
</html>
对于写的小项目完成添加删除后,想要在页面显示添加成功等信息时,可以利用下面的代码来实现
<script type="text/javascript">
window.onload = function(){
if (${info != null}){
alert("${info}");
}
}
</script>