晚饭后,有人在发疑问为啥编写的Struts里面的表单验证代码死活不会执行。原始代码如下:
<%@page contentType="text/html;charset=gb2312"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<html:html>
<head>
<title>welcome next</title>
</head>
<body>
<center>
注销页面
<html:form action="/delete" enctype="multipart/form-data" onsubmit="return delete(this);">
用户名:<html:text property="username"/><br>
年 龄:<html:text property="age" value=""/><br>
地 址:<html:text property="address"/>
<br>
<html:submit value="注销"/>
<html:form>
</center>
<script language="javascript"> 1:
2: function delete(form){
3: if(form.username.value==""||form.age.value==""||form.address.value==""){
4: alert("请输入所有的信息!!!");
5: return false;
6: }
7: else{
8: alert("注销成功!!!");
9: return true;
10: }
11: }
</script>
</body>
</html:html>
运行症状就是不管怎么搞,都不会执行验证方法!对应的HTML代码如下:
<html>
<head>
<title>welcome next</title>
</head>
<body>
<center>
注销页面
<form name="deleteForm" method="post" action="/DataBaseStruts/delete.do" enctype="multipart/form-data" onsubmit="return delete(this);">
用户名:<input type="text" name="username" value=""><br>
年 龄:<input type="text" name="age" value=""><br>
地 址:<input type="text" name="address" value="">
<br>
<input type="submit" value="注销">
</form>
</center>
<script language="javascript">
function delete(form){
if(form.username.value==""||form.age.value==""||form.address.value==""){
alert("请输入所有的信息!!!");
return false;
}
else{
alert("注销成功!!!");
return true;
}
return true;
}
</script>
</body>
</html>
把这个页面存成HTML代码,不论在IE还是Firefox中,都不会执行!但是又不报任何错误!难道我们写错了嘛?那当然,这个错误真是特别特别的隐蔽,因为:delete是个JavaScript的关键字!
发表于 @ 2008年03月13日 10:14:00|评论(loading...)|编辑