• 重写form 表单的验证信息



    (function($) {
    var isformValidationPostBack=true;
    var isformValidation = false;
    $.extend({
    formValidationDiv: function(formID) {
    if(isformValidationPostBack){
    var h='<div style="160px;height:40px;background-color:#F0F8FF;z-index:20;position:absolute;display: none;box-shadow: 1px 1px 3px gray;" id="submitValidate">'
    h+='<div style="position: relative;top: -23px;0px;height: 0px;border-top:12px solid transparent;border-left:12px solid transparent;border-bottom:12px solid rgb(240, 248, 255);border-right:12px solid transparent;"></div>'
    h+='<div style=" position: relative;top: -13px;"> <i id="file_i" class="fa fa-exclamation-triangle" style="color:#FF8C00;font-size:22px;margin-top: -1px;margin-left: 4px;"></i><label style="margin-left: 10px;vertical-align: top;color:black"></label></div></div>'
    $("body").append(h);
    isformValidationPostBack=false
    }

    var alltxt = $("#"+formID).find("input");
    for (var i=0;i<alltxt.length;i++) {
    var thisTop =alltxt[i].getBoundingClientRect();
    var thisHeight = alltxt[i].getBoundingClientRect().height;
    var thisPattern = alltxt[i].getAttribute("pattern");
    var reg = new RegExp(thisPattern);
    if(alltxt[i].getAttribute("required")) { //非空验证
    if(alltxt[i].value == "") {
    $("#submitValidate").css({
    "top": (thisTop.top + thisHeight + 17),
    "left": thisTop.left,
    "width": (44 + alltxt[i].getAttribute("data-miss").length * 16)
    })

    $("#submitValidate").find("label").text(alltxt[i].getAttribute("data-miss"));
    $("#submitValidate").show()
    isformValidation=false
    break
    } else if(alltxt[i].getAttribute("pattern")) { //规则验证
    if(!reg.test(alltxt[i].value)) {
    $("#submitValidate").css({
    "top": (thisTop.top + thisHeight + 17),
    "left": thisTop.left,
    "width": (44 + alltxt[i].getAttribute("data-miss").length * 16)
    })

    $("#submitValidate").find("label").text(alltxt[i].getAttribute("data-pattern"))
    $("#submitValidate").show()
    isformValidation=false
    break
    }else{
    isformValidation=true;
    }
    } else {
    $("#submitValidate").hide();
    isformValidation=true;
    }
    }
    }

    return isformValidation;
    }
    })
    })(jQuery)

      2.当ajax提交表单时调用

    $("#btnt").click(function(){
    					alert(jQuery.formValidationDiv("test"));//如果通过了验证就返回true  否则就返回false 
    				})
    

      3.html

    <div id="test">
    <form>
    <input type="text" id="one" required="required" data-miss="姓名是顶顶顶顶顶是打发第三方是必填字段" data-pattern="请输入三个字母" pattern="[A-Za-z]{3}" />
    <input type="text" id="two" required="required" data-miss="性别是必填字段" />
    <input type="text" id="three" />
    <input type="button" value="测试" id="btn" />
    <input type="button" value="测试插件" id="btnt"/>
    <input type="submit" />
    </form>
    </div>

    <!--<div style="160px;height:40px;background-color:#F0F8FF;z-index:20;position:absolute;display: none;box-shadow: 1px 1px 3px gray;" id="submitValidate">
    <div style="position: relative;top: -23px;0px;height: 0px;border-top:12px solid transparent;border-left:12px solid transparent;border-bottom:12px solid rgb(240, 248, 255);border-right:12px solid transparent;"></div>
    <div style=" position: relative;top: -13px;"> <i id="file_i" class="fa fa-exclamation-triangle" style="color:#FF8C00;font-size:22px;margin-top: -1px;margin-left: 4px;"></i><label style="margin-left: 10px;vertical-align: top;color:black"></label></div>
    </div>-->

      

  • 相关阅读:
    mac Navicat连接Oracle报错ORA-21561: OID generation failed
    svn: E230001: Server SSL certificate verification failed: certificate issued
    mac删除系统应用出现mac Read-Only filesystem
    spring boot项目03:阅读启动源码
    spring boot项目02:Web项目(基础)
    spring boot项目01:非Web项目(基础)
    idea 单独引入jar_Iidea 单独引入jar_Intellij IDEA 添加jar包的三种方式ntellij IDEA 添加jar包的三种方式
    java输出pdf的依赖包,非maven,包名:spire.pdf.jar 下载
    IDEA Error:java: 无效的源发行版: 11错误
    SpringBoot官网以下载模板方式创建
  • 原文地址:https://www.cnblogs.com/lgjc/p/6192997.html
Copyright © 2020-2023  润新知