JavaScript注册页面表单校验完善

<script type="text/javascript">
			/* function showTips() {
				document.getElementById("userspan").innerHTML="<font color='navy'>用户名必填!</font>";
			}
			
			function checkUser() {
				//获取用户输入的用户名
				var uValue = document.getElementById("user").value;
				//进行校验
				if(uValue=="") {
					document.getElementById("userspan").innerHTML="<font color='red'>用户名不能为空!</font>";
				} else {
					document.getElementById("userspan").innerHTML=""; 
				}
			} */
			
			function showTips(id,info) {
				document.getElementById(id+"span").innerHTML="<font color='navy'>"+info+"</font>";
			}
			
			function check(id,info) {
				//获取用户输入的用户名
				var value = document.getElementById(id).value;
				//进行校验
				if(value=="") {
					document.getElementById(id+"span").innerHTML="<font color='red'>"+info+"</font>";
				} else {
					document.getElementById(id+"span").innerHTML=""; 
				}
			}
			
		</script>
<tr>
								<td>
									用户名
								</td>
								<td>
									<input οnblur="check('user','用户名不能为空!')" οnfοcus="showTips('user','用户名必填!')" type="text" name="user" size="34px" id="user"/>
									<span id="userspan"></span>
								</td>
							</tr>
							<tr>
								<td>
									密码
								</td>
								<td>
									<input οnblur="check('password','密码不能为空!')" οnfοcus="showTips('password','密码必填!')" type="password" name="password" id="password" size="34px"/>
									<span id="passwordspan"></span>
								</td>
							</tr>
发布了120 篇原创文章 · 获赞 9 · 访问量 4313

猜你喜欢

转载自blog.csdn.net/HuashirenYty/article/details/102699839