日期:2014-05-16 浏览次数:20485 次
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%> <%@ taglib prefix="s" uri="/struts-tags"%> <!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=GBK"> <script type="text/javascript" src="js/checkUser.js"></script> <title>Insert title here</title> </head> <body> <!-- 添加用户的Action --> <s:form action="actions/User_add" method="post" onsubmit="return checkUserAdd();"> <table width="50%" align="center"> <tr align="center"> <td> <s:textfield id="name" label="用户名" name="name"></s:textfield> </td> </tr> <tr align="center"> <td> <s:textfield id="age" label="年龄" name="age"></s:textfield> </td> </tr> <tr align="center"> <s:textfield id="joinDate" label="日期" name="joinDate"></s:textfield> </tr> <s:submit value="提交" ></s:submit> <s:reset type="重置"></s:reset> </table> </s:form> </body> </html>
// 检测用户输入 function checkUserAdd() { var form=document.forms[0]; var n=form.name.value; var age=form.age.value; var joinDate=form.joinDate.value; if(n=="") { alert("用户名为不能为空"); return false; }else { alert("用户名为:"+n); } if(age=="") { alert("年龄为不能为空"); return false; }else { alert("年龄名为:"+age); } if(joinDate=="") { alert("日期不能为空"); return false; }else { alert("日期为:"+joinDate); } return true; }