zoukankan      html  css  js  c++  java
  • Form表单利用Jquery Validate验证以及ajax提交

    #表单利用Jquery验证验证以及ajax提交

    概述>详细讲解表单利用Jquery >验证验证以及ajax提交的过程,以及Validate的自定义提示语,非空判断,输入字段的远程ajax验证等

    。———-
    环境准备在html中引入四个js文件(jquery文件,jquery.form文件,jquery.validate文件,jquery.validate.extend文件):

    <script src =“/ jquery / jquery-1.8.3.min.js”type =“text / javascript”> </ script> 
    <script src =“/ jquery / jQuery.Form.js” type =“text / javascript”> </ script> 
    <script type =“text / javascript”src =“/ jquery / jquery.validate.js”charset =“UTF-8”> </ script> 
    <script type =“ text / javascript“src =”/ jquery / jquery。validate.extend.js“charset =”UTF-8“> </ script> ```
    下载地址:[
    
    jQuery插件之窗体:http://download.csdn.net/detail/s445320/9438163 ](http://download.csdn.net/detail/s445320/9438163 )[ jquery-1.8.3.min.js:http ://download.csdn.net/detail/s445320/9438161 ](http://download.csdn.net/detail/s445320/9438161 )[ jquery.validate.js:http://download.csdn.net/detail / s445320 / 9612201 ](http://download.csdn.net/detail/s445320/9612201 )[ jquery.validate.extend.js:http://download.csdn.net/detail/s445320/9616989 ](http: //download.csdn.net/detail/s445320/9616989 )   - **编写html区域(form及input)**
    
    
    
    
    
    
     ```
    <form id =“inputForm”name =“inputForm”action =“../ xxxx / xxxxaccount”method =“post”novalidate =“novalidate”> 
    <input type =“text”name =“name”id =“name” class =“form-control required”value =“刘伟”onfocus = this.blur()> 
    </ form> ``` 
    - **
    
    
    
    
    编写Javascript表单验证区域** ```
     <script type =“text / javascript “> 
      $(document).ready(
        function(){ 
          $(”#inputForm“)。validate({ 
            submitHandler:function(form){//验证通过后的执行方法
                //当前的窗体通过ajax方式提交(用到jQuery.Form文件)
                $(form).ajaxSubmit({ 
                    dataType:“json”,
                    成功:函数(jsondata){ 
                        if(jsondata.code = 200){
                            alert("success");
                        }else{
                            alert("fail");
                        }
                      }
                    }); 
    
            },
            focusInvalid : true,   //验证提示时,鼠标光标指向提示的input
            rules : {  //验证尺度  
              account : {  
                required : true,   //验证非空
                remote: {          //远程ajax验证
                    url: "../xxxx/checkaccount", //检查是否存在账号,存在则返回true
                    type: "GET",
                    dataType: "json",
                    data: {
                        account: function () {
                            return $("#account").val(); //这个是取要验证的用户名
                        }
                    },
                    dataFilter: function (data) {  //判断控制器返回的内容
                        var notice = eval("("+ data +")");
                        if( notice ){
                            return false;
                        }else{
                            return true;
                        }
                    }
                }
              },  
            },  
            messages : {  
              account : {  
                required : "用户名不能为空",
                remote: "用户名已存在!"  //这个地方如果不写的话,是自带的提示内容,加上就是这个内容。
              }
            },  
            errorElement : "div",
            errorClass : "error_info",
            highlight : function(element, errorClass,
                validClass) {
              $(element).closest('.form-control').addClass(
                  'highlight_red');
            },
            success : function(element) {
              $(element).siblings('.form-control')
                  .removeClass('highlight_red');
              $(element).siblings('.form-control').addClass(
                  'highlight_green');
              $(element).remove();
            }
    
          });
        });
    </script>



    效果图如下:

    原文链接:https://blog.csdn.net/s445320/article/details/50748975

  • 相关阅读:
    Uliweb模板分析
    从高宏伟处借来的HOOK API代码
    ActiveX获取脚本对象
    uliweb数据库分析
    Java初入门(from c++ 2 java)(一)
    VS2010调试sharepoint2010经常Web服务器进程由IIS终止 的解决办法
    SharePoint 2010 部署 WSP 包
    sharepoint 2010 "若要在 Visual Studio 中与 SharePoint 项目进行交互,您的系统用户帐户必须拥有管理员特权。"的解决方法
    SQL 2008 安装问题 共享功能目录(x86) 服务提供的凭据无效 解决版本
    SharePoint 2010 网站集 备份 还原
  • 原文地址:https://www.cnblogs.com/isme-zjh/p/11880900.html
Copyright © 2011-2022 走看看