我想校验类型名称和培训周期 ,可是我写到这后, 就不会了,不好使,该怎么解决,就是在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> $("#trainTypeForm").validate({<br> rules:{<br> "trainType.trainTypeName":{<br> required:true<br> },<br> "trainType.trainPeriod":{<br> required:true,<br> number:true<br> }<br> },<br> messages:{<br> "trainType.trainTypeName":{<br> required:"填写培训类型名称!"<br> }<br> "trainType.trainPeriod":{<br> required:"填写培训周期!",<br> number:"培训周期必须为数字"<br> },<br> },</p> <pre><code> focusInvalid:true, onkeyup:true, errorPlacement: function(error, element) { error.appendTo( element.parent()); } }); }); </script> </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> <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> ${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> <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> <br> </td><br> <td width="36%"><br> <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> <br> <s:submit value="新增同级" method="addSame"/><br> <br> <s:submit value="新增下级" method="addLow"/><br><br> <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不给你提示吗?我改好了,这样就没有问题了。