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

it2026-06-09  2

trim()它是去掉字符串左右空格失去焦点事件 blur(function(){})click(function(){}) 点击事件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>
最新回复(0)