zoukankan      html  css  js  c++  java
  • 重写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>-->

      

  • 相关阅读:
    网站如何做分布式(集群)的大纲
    [转]Bind和Eval的区别详解
    SQL 中游标的并发问题。
    如何利用客户端缓存对网站进行优化?
    Windows的第五种群集方案 CCS
    ICollection 接口的类序列化的问题。
    如何提高网页的效率(上篇)——提高网页效率的14条准则
    石油地质名称解释
    【SQL基础概念】
    DataView/DataRowView
  • 原文地址:https://www.cnblogs.com/lgjc/p/6192997.html
Copyright © 2011-2022 走看看