为什么javascript不起作用呢!?
我用的是struts框架,有一个注册表单,为什么我写的javascript验证这个表单不起作用呢?下面是代码!
<%@ page language= "java " pageEncoding= "gb2312 " %>
<%@ taglib uri= "http://jakarta.apache.org/struts/tags-bean " prefix= "bean "%>
<%@ taglib uri= "http://jakarta.apache.org/struts/tags-html " prefix= "html "%>
<html>
<head>
<script language= "javascript ">
function checkform(form){
if (form.userName){
if (form.userName.value== " ")
{
alert ( "请输入用户名 ");
form.userName.focus();
return (false);
}
}
if(form.password){
if(form.password.value== " ")
{
alert ( "输入密码 ");
form.password.focus();
return (false);
}
}
if(form.psw){
if(form.psw.value!=form.password.value)
{
alert ( "两次密码不一样 ");
form.psw.focus();
return (false);
}
}
if (form.email){
if (form.email.value == " "||form.email.value.indexOf( "@ ")==-1){
alert( "请输入合适的E-MAIL地址! ");
form.email.focus();
return (false);
}
}
</script>
</head>
<body>
<html:form action= "/register " method= "post " >
<table width= "43% " border=1 align= "center " cellpadding= "0 " cellspacing= "0 ">
<tr>
<td> 用户名: </td>
<td> <html:text property= "userName " size= "20 "/> <br> </td>
</tr>
<tr>
<td> 密码: <br> </td>
<td> <html:password property= "password " size= "20 "/> <br> </td>
</tr>
<tr>
<td> 确认密码: <br> </td>
<td> <html:password property= "psw "/> <br> </td>
</tr>
<tr>
<td> 年龄: <br> </td>
<td> <html:text property= "age "/> <br> </td>
</tr>
<tr>
<td> 性别: <br> </td>
<td> <html:radio property= "sex " value= "male "/> 男
<html:radio property= "sex " value= "female "/> 女 </td>
</tr>
<tr>
<td> 职业: <br> </td>
<td> <html:select property= "carrer "> <html:option value= "老师 "> 老师 </html:option>
<html:option value= "记者 "> 记者 </html:option>
<html:option value= "学生 "> 学生 </html:option>
<html:option value= "商人 "> 商人 </html:option>
<html:option value= "农民 "> 农民 </html:option>
<html:option value= "工人 "> 工人 </html:option>
<html:option value= "医生 "> 医生 </html:option>
<html:option value= "其他 "> 其他 </html:option>
</html:select> <br> </td>
</