日期:2014-05-16 浏览次数:20720 次
html
<form id="form" >
??? <label for="cName">
???? 用户名
??? </label>
??? <label for="cName" > 我们要测试</label>
??? <input id="cName1" name="cName" >
??? <input type="submit" value="Test" />
</form>
-------
<script type="text/javascript">
$.validator.setDefaults({??????
???? submitHandler: function(form) {???
???????? form.submit();???
??? }??????
});
$(document).ready(function() {
?? function showRequest()
?? {???
???? var isSuccess=$("#form").validate().form(); //.form(); 返回是否验证成功
?????? return isSuccess;
?? }
?? function showResponse(responseText, statusText, xhr, $form) {
??? if (responseText) {
???? alert(responseText);
??? }
?? }
??? var options={
????? beforeSubmit: showRequest,
????? success : showResponse
?????? }
?? $("#form").ajaxForm(options);
??
?? $("#form").validate( {
??? rules : {
???? cName : "required"
??? },
??? messages : {
???? cName :"请输入值"
??? }
?? });
});
</script>