日期:2014-05-16  浏览次数:20549 次

jquery-validate的问题
我想要验证培训名称和培训周期,我就能写到这了,不好使,再往后不了,还应该怎么写才对,在textfield后面显示错误信息,要红色的字

JScript code
<%@ 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">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>培训类型管理</title>
    <script type="text/javascript" src="../commons/js/global.js"></script>
    <script type="text/javascript" src="../commons/widget/jquery/jquery.js"></script>
    <script type="text/javascript" src="../commons/widget/jquery/jquery.validate.pack.js"></script>
    <script type="text/javascript">
    $(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());      
            }      
            
        });
    });
    </script>
</head>
<body>
    <link rel="stylesheet" type="text/css" href="../commons/css/css.css"></link>    
    <s:form id="trainTypeForm" name="trainTypeForm" method="post">
    <s:hidden name="trainType.trainTypeId" id="trainTypeId"/>
        <table width="600" align="center" border="0" cellpadding="0"
            cellspacing="0" bgcolor="#666699">
            <tr>
                <td>
                    <table width="100%" border="0" cellspacing="1" cellpadding="0"
                        class="style2">
                        <tr bgcolor="#f3f7ff" height="24">
                            <td width="15%" bgcolor="#E0ECF8" align="center">
                                培训类型名称:
                            </td>
                            <td width="35%">
                                &nbsp;
                                <s:textfield name="trainType.trainTypeName" id="trainType.trainTypeName"></s:textfield>                    
                            </td>
                            <td width="15%" bgcolor="#E0ECF8" align="center">
                                上级培训类型:
                            </td>
                            <td width="35%">
                                &nbsp;${upTrainTypeName}<s:hidden name="trainType.upTrainTypeId" id="upTrainTypeId"></s:hidden>
                            </td>