温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

jqueryFormvalidator Ajax修改数据验证是否存在

发布时间:2020-05-29 03:23:01 来源:网络 阅读:876 作者:kafeihouye 栏目:web开发

 

  1. var accErrorMsg = "请输入客户分类名称"
  2. //表单数据验证 
  3. $(function(){ 
  4.                 //$.formValidator.initConfig({formid:"myform",autotip:true});    
  5.         $.formValidator.initConfig({ 
  6.                     formid:"myform", 
  7.                     autotip:true 
  8.                 }); 
  9.                  
  10.                 $("#name").formValidator({ 
  11.                 onshow:"请输入客户分类名称", 
  12.                 onfocus:"2至20个字符", 
  13.                 oncorrect:"输入正确"}).functionValidator({ 
  14.                                         fun: function(){ 
  15.                                             var roleName = $("#name").val(); 
  16.                                             if(trim(roleName)=="") 
  17.                                             { 
  18.                                                  accErrorMsg = "请输入客户分类名称"
  19.                                                  return accErrorMsg; 
  20.                                             }else if(trim(roleName).length==1 ||trim(roleName).length>20){ 
  21.                                                  accErrorMsg="2至20个字符"
  22.                                                  return accErrorMsg; 
  23.                                             } 
  24.                                             else 
  25.                                             {                                                
  26.                                                 return true; 
  27.                                             } 
  28.                                         } 
  29.                                     }).ajaxValidator({ 
  30.                                         type:"post", 
  31.                                         url: "${basePath}clientSortSTManage/clientSortST!isClientSortNameExist.action", 
  32.                                         datatype: "json", 
  33.                                         timeout: 3000,   
  34.                                         success: function(data) 
  35.                                         { 
  36.                                             //将老角色名与新角色名比较,如果一样判为通过 
  37.                                             var oldName = $('#oldName').val(); 
  38.                                          
  39.                                             var rName = $('#name').val();    
  40.                                             if(oldName && oldName==rName) 
  41.                                             { 
  42.                                                 return true; 
  43.                                             }        
  44.                                          
  45.                                             //根据ajax返回结果判断       
  46.                                             var correct = data.correct; 
  47.                                             if(correct) 
  48.                                             { 
  49.                                                 return true; 
  50.                                             } 
  51.                                             else 
  52.                                             { 
  53.                                                 return false; 
  54.                                             } 
  55.                                              
  56.                                              
  57.                                         },                               
  58.                                         error: function() 
  59.                                         { 
  60.                                             artalert("服务繁忙,请稍后再试!"); 
  61.                                         }, 
  62.                                         onerror : "客户分类名称已存在,请更换客户分类名称", 
  63.                                         onwait : "正在对客户分类名称进行校验,请稍候…" 
  64.                                     }).defaultPassed(); 
  65. }) 

 

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI