我想顯示這個效果,但實際是一點提交,顯示“請輸入聯系電話!”我的代碼如下//登錄表單驗證?$(document).ready(function(){ ? $("#submitForm").validate({ rules: { ?company: {? ? ? ? ? ? ? ? ? ? ?required: true,? ? ? ? ? ? ? ? ? ? minlength: 2,? ? ? ? ? ? ? ? ? ? maxlength: 10 ? ? ? ? ? ? ? ? }, ? ? user: {? ? ? ? ? ? ? ? ? ? ?required: true,? ? ? ? ? ? ? ? ? ? minlength: 2,? ? ? ? ? ? ? ? ? ? maxlength: 10 ? ? ? ? ? ? ? ? }, ? ? phone: {? ? ? ? ? ? ? ? ? ? ?required: true,? ? ? ? ? ? ? ? ? ? ? isPhone: true ? ? ? ? ? ? ? ? ? } }, messages: { company: {? ? ? ? ? ? ? ? ? ? ?required: '請輸入公司名稱!',? ? ? ? ? ? ? ? ? ? minlength: '公司名稱不能小于2個字符!',? ? ? ? ? ? ? ? ? ? maxlength: '公司名稱不能超過10個字符!' ? ? ? ? ? ? ? ??? ? ? ? ? ? ? ? }, ? user: {? ? ? ? ? ? ? ? ? ? ?required: '請輸入聯系人姓名!',? ? ? ? ? ? ? ? ? ? minlength: '公司名稱不能小于2個字符!',? ? ? ? ? ? ? ? ? ? maxlength: '公司名稱不能超過10個字符!' ? ? ? ? ? ? ?? ? ? ? ? ? ? ? }, ? phone: { required: '請輸入聯系電話!', ?isPhone: '請輸入一個有效的聯系電話!' ? ? ? ? ? ?? } }, submitHandler: function (form) { ? ? ?//通過驗證,運行函數? ? ? ? ? ? ? ? console.log($(form).serialize()); ? ? ? ? //form表單序列號? ? ? ? }, groups:{ login:"company user phone" }, errorPlacement:function(error,element){ error.appendTo("#error_tip"); }, errorElement: "em", //用來創建錯誤提示信息標簽 ?});? });??? // 聯系電話(手機/電話皆可)驗證?jQuery.validator.addMethod("isPhone", function(value,element) {?? var mobile = /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/;?? var tel = /^\d{3,4}-?\d{7,9}$/;?? return this.optional(element) || (tel.test(value) || mobile.test(value));?});?
- 3 回答
- 0 關注
- 1775 瀏覽
添加回答
舉報
0/150
提交
取消