HTML(HBuilder)作业题10- 用户登录(jquery)

  • Post author:
  • Post category:其他



问:简单的用户登录怎么弄

答:

1.利用jquery

2.利用if

注释:用鼠标离开区域开始判断(可以自行尝试修改成click单击按钮)


HBuilder

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="../js/jquery-3.5.1.js" type="text/javascript"></script>
		<style>
			div{height: 30px;}
		</style>
	</head>
	<body>
		<form id="Form">			
			<div>用户名:<input type="text" id="User_name" name="User_name" autocomplete="off" placeholder="请输入用户名"/><font color="red">*</font></div>
			<div>密--码:<input type="password" id="Password" name="Password" placeholder="请输入密码"/><font color="red">*</font></div>
			<div>性--别:
				<input type="radio" id="sex" name="XB" value="男" />男---
				<input type="radio" id="sex" name="XB" value="女" />女
			</div>
			<div>年--龄:<input type="text" id="age" name="age" size=4 maxlength=3 /></div>
			<div><input type="submit" name="sub" value="注册" /></div>
		</form>
		<script>
			$(document).ready(function() {
				$("#Form input").blur(function() {
					if ($(this).is("#User_name")) {
						if ($(this).val() == "") {
							alert("用户名不能为空");
						}
					}
					if ($(this).is("#Password")) {
						if ($(this).val() == "") {
							alert("密码不能空");
						}
						if ($(this).val().length < 8) {
							alert("密码不能少于8位 \n当前输入密码" + $(this).val().length + "位");
						}
					}
					if ($(this).is("#Password")) {
						if ($(this).val() == "") {
							alert("年龄不能小于18");
						}
					}
				})
			})
		</script>
		</script>
	</body>
</html>

————分割线—————

菜鸟古古 2022-1-4 09:59:49



版权声明:本文为qq_28085027原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。