表单过滤选择器(表单练习)

  1. trim()它是去掉字符串左右空格
  2. 失去焦点事件 blur(function(){})
  3. click(function(){}) 点击事件
  4. submit() 表单提交
<%@ 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="../jquery/jquery-1.8.3.js"></script>
<script type="text/javascript">
	$(function () {
		//当username与password失去焦点后,判断录入的数据不能为空
		$(":text,:password").blur(function () {
			//获取数据
			var value=$(this).val();
			if(value.trim()==""){
				alert($(this).attr("name")+"不可以为空");
			}
		})
		//为button添加点击事件,提交form表单
		$(":button").click(function() {
			$("form").submit();
		})
	});
</script>
</head>
<body>
	<form action="/web_test2/jsp/list.jsp">
	用户名:<input type="text" name="username" /><br/>
	密码:<input type="password" name="pwd" /><br/>
	<input type="button" value="提交" />
	</form>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_43566782/article/details/109227987
今日推荐