读书人

jquery-validate的用法解决思路

发布时间: 2012-08-16 12:02:15 作者: rapoo

jquery-validate的用法
我有这样一段代码,想要表单验证,如果验证不通过,怎么显示在输入框旁边?<script>

JScript code
$(function(){            $("#trainTypeForm").validate({                rules:{                    "trainType.trainTypeName":{                        required:true                    }                    "trainType.trainPeriod":{                        required:true,                        number:true                    }                                },                message:{                    "trainType.trainTypeName":{                        required:"培训类型名称必须填写!",                    }                    "trainType.trainPeriod":{                        required:"培训周期必须填写!",                        number:"必须为数字"                    }                }                        });        });        </script>         <body>             <s:form id="trainTypeForm" method="post" action="">               <table>                <tr><td>                    <s:textfield name="trainType.trainTypeName" id="trainTypeName">                </td></tr>               </table>             </s:form>         </body>


[解决办法]
小做改动即可。。

JScript code
<script>$(function(){            $("#trainTypeForm").validate({                rules:{                    "trainType.trainTypeName":{                        required:true                    }                    "trainType.trainPeriod":{                        required:true,                        number:true                    }                                },                message:{                    "trainType.trainTypeName":{                        required:"培训类型名称必须填写!",                    }                    "trainType.trainPeriod":{                        required:"培训周期必须填写!",                        number:"必须为数字"                    }                },                errorPlacement: function(error, element) {                          error.appendTo( element.parent());                           },                         });        });        </script>
[解决办法]
你看看这篇文章吧。。。
http://blog.csdn.net/lxf9601/article/details/5863728
上个月,我的项目中,领导也要求使用了jquery的validate框架。。。
我就是从上面那篇博客看到的。好使得很。。。
至于楼主你那里为什么不好使的话,要看看你代码里面的实际情况了。也许也和你使用的struts框架生成的一大堆垃圾代码有关系吧。。。


楼主,你好好研究研究这篇博客吧,相信你能解决问题的。。。

读书人网 >J2EE开发

热点推荐