jquery-validate验证问题

我想校验类型名称和培训周期 ,可是我写到这后, 就不会了,不好使,该怎么解决,就是在textfield后显示错误信息

[code="java"]<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



培训类型管理



<br> $(document).ready(function(){<br> $(&quot;#trainTypeForm&quot;).validate({<br> rules:{<br> &quot;trainType.trainTypeName&quot;:{<br> required:true<br> },<br> &quot;trainType.trainPeriod&quot;:{<br> required:true,<br> number:true<br> }<br> },<br> messages:{<br> &quot;trainType.trainTypeName&quot;:{<br> required:&quot;填写培训类型名称!&quot;<br> }<br> &quot;trainType.trainPeriod&quot;:{<br> required:&quot;填写培训周期!&quot;,<br> number:&quot;培训周期必须为数字&quot;<br> },<br> },</p> <pre><code> focusInvalid:true, onkeyup:true, errorPlacement: function(error, element) { error.appendTo( element.parent()); } }); }); &lt;/script&gt; </code></pre> <p></head><br> <body><br> <link rel="stylesheet" type="text/css" href="../commons/css/css.css"></link><br><br> <s:form id="trainTypeForm" name="trainTypeForm" method="post"><br> <s:hidden name="trainType.trainTypeId" id="trainTypeId"/><br> <table width="600" align="center" border="0" cellpadding="0"<br> cellspacing="0" bgcolor="#666699"><br> <tr><br> <td><br> <table width="100%" border="0" cellspacing="1" cellpadding="0"<br> class="style2"><br> <tr bgcolor="#f3f7ff" height="24"><br> <td width="15%" bgcolor="#E0ECF8" align="center"><br> 培训类型名称:<br> </td><br> <td width="35%"><br> &nbsp;<br> <s:textfield name="trainType.trainTypeName" id="trainType.trainTypeName"><a href="/s:textfield">/s:textfield</a><br><br> </td><br> <td width="15%" bgcolor="#E0ECF8" align="center"><br> 上级培训类型:<br> </td><br> <td width="35%"><br> &nbsp;${upTrainTypeName}<s:hidden name="trainType.upTrainTypeId" id="upTrainTypeId"><a href="/s:hidden">/s:hidden</a><br> </td><br> </tr><br> <tr bgcolor="#f3f7ff" height="24"><br> <td width="12%" bgcolor="#E0ECF8" align="center"><br> 培训周期:<br> </td><br> <td width="40%"><br> &nbsp;<br> <s:textfield name="trainType.trainPeriod" id="trainType.trainPeriod"><a href="/s:textfield">/s:textfield</a><br><br> </td><br> <td width="12%" bgcolor="#E0ECF8" align="center"><br> &nbsp;<br> </td><br> <td width="36%"><br> &nbsp;<br> </td><br> </tr><br> </table><br> <table width="100%" border="0" cellspacing="1" cellpadding="0"<br> bgcolor="#FFFFFF"><br> <tr align="center"><br> <td><br> <s:submit value="修改" method="update"/><br> &nbsp;<br> <s:submit value="新增同级" method="addSame"/><br> &nbsp;<br> <s:submit value="新增下级" method="addLow"/><br><br> &nbsp;<br> <s:submit value="删除" method="remove"/><br><br> </td><br> </tr><br> </table><br> </td><br> </tr><br> </table><br> <a href="/s:form">/s:form</a><br> </body>[/code]</p>

不用转义:"trainType.trainTypeName": "required",这样配置
哥们代码:
[code="html"]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


Mini-Web 角色管理
$(document).ready(function() { //为inputForm注册validate函数 $("#inputForm").validate({ rules: { "trainType.trainTypeName": "required", "trainType.upTrainTypeId": "required", "trainType.trainPeriod": "required" }, messages: { "trainType.trainTypeName": { required: "培训类型名称" }, "trainType.upTrainTypeId": { required: "上级培训类型" }, "trainType.trainPeriod": { required: "培训周期" } } }); });

培训类型名称: 上级培训类型:
培训周期:   


[/code]

trainType.trainTypeName
把这个. 换成. 加上转义!

[url]http://hi.baidu.com/fxliju/item/d35e64ce0871143298b498ee[/url] api

看这个连接
http://hi.baidu.com/fxlijun/item/d35e64ce0871143298b498ee

[code="js"]
$(document).ready(function(){

$("#trainTypeForm").validate({

rules:{

"trainType.trainTypeName":{

required:true

},

"trainType.trainPeriod":{

required:true,

number:true

}

},

messages:{

"trainType.trainTypeName":{

required:"填写培训类型名称!"

} ,

"trainType.trainPeriod":{

required:"填写培训周期!",

number:"培训周期必须为数字"

}

},

       focusInvalid:true,   
        onkeyup:true,   

        errorPlacement: function(error, element) {     
            error.appendTo( element.parent());         
       }                  
    });   
}); 

[/code]

你有一个地方没有加逗号,有些个逗号的编码不一样,你的eclipse不给你提示吗?我改好了,这样就没有问题了。