(function($) {
var isformValidationPostBack=true;
var isformValidation = false;
$.extend({
formValidationDiv: function(formID) {
if(isformValidationPostBack){
var h='<div style="width: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;width: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="\b[A-Za-z]{3}\b" />
<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="width: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;width: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>-->

  

重写form 表单的验证信息的更多相关文章

  1. 深入了解Element Form表单动态验证问题 转载

    随风丶逆风 2020-04-03 15:36:41  2208  收藏 3 分类专栏: Vue 随笔 文章标签: 动态验证 el-form elementUI 表单验证 版权 在上一篇<vue ...

  2. form 表单jquery验证插件使用

    第一部分:表单样式 <form action="#" method="post" id="regist">   <tabl ...

  3. Vue Element Form表单时间验证控件使用

    如果直接使用Element做时间选择器,其规则(rules)不添加type:'date',会提示类型错误,处理这个需要规范值的类型为date. 时间格式化过滤器 import Vue from 'vu ...

  4. a链接易混淆与form表单简易验证用法详解

    链接可以说遍布互联网,比如你想提供一个可以跳转到百度首页的链接给网友,那么代码如下: <a href="http://www.baidu.com">百度一下,你就知道& ...

  5. form表单点击后验证

    function check(){ var customertype = document.getElementById("customertype"); //alert(cust ...

  6. element-ui Form表单验证

    element-ui Form表单验证规则全解 element的form表单非常好用,自带了验证规则,用起来很方便,官网给的案例对于一些普通场景完全没问题,不过一些复杂场景的验证还得自己多看文档摸索, ...

  7. Django学习笔记(6)——Form表单

    知识储备:HTML表单form学习 表单,在前端页面中属于最常见的一个东西了.基本上网站信息的提交都用到了表单,所以下面来学习Django中优雅的表单系统:Form 表单的主要作用是在网页上提供一个图 ...

  8. js阻止form表单重复提交

    防止表单重复提交的方法总体来说有两种,一种是在js中阻止重复提交:另一种是在后台利用token令牌实现,大致思路是生成一个随机码放到session和form表单的隐藏输入框中,提交表单时两者对比,表单 ...

  9. java:JavaScript2:(setTimeout定时器,history.go()前进/后退,navigator.userAgent判断浏览器,location.href,五种方法获取标签属性,setAttribute,innerHTML,三种方法获取form表单信息,JS表单验证,DOM对象,form表单操作)

    1.open,setTimeout,setInterval,clearInterval,clearTimeout <!DOCTYPE> <html> <head> ...

随机推荐

  1. POJ 3667 Hotel(线段树 区间合并)

    Hotel 转载自:http://www.cnblogs.com/scau20110726/archive/2013/05/07/3065418.html [题目链接]Hotel [题目类型]线段树 ...

  2. 有关TabBar的一些性质

    // 计入导航控制器时,要使得底部的TabBar消消失 test.hidesBottomBarWhenPushed = YES; /** *  布局子控件 */ - (void)layoutSubvi ...

  3. android 代码设置progressBar 颜色

    void test() { LinearLayout linearLayout = new LinearLayout(this); ProgressBar progressBar = new Prog ...

  4. css相对定位+浮动实现元素位置互换

    1.设置元素透明度 opacity:0.5; // w3c filter:alpha(opacity=50); //IE 2 position:relative; float:left; 一起使用的效 ...

  5. mac 下打开多个Eclipse

    在Mac下只能打开一个Eclipse工具. 使用下面命令,在控制台中输入,可以打开多个Eclipse. open -n xx/xx/eclipse.app 例子: open -n /Users/use ...

  6. SplendidCRM中给来自EditView中的listbox控件设置选中值或数据源

    DropDownList list = this.findContol("aas") as DropDownList;list.DataSource = new DataTable ...

  7. QT不同版本编译

    QT发布了不同版本,有一些语法修改,需要修改代码.同时旧版本代码转换需要在pro文件中添加代码greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

  8. Jmeter beanshell 生成手机号加密签名

    首先自己写一个根据手机号生成加密字符串的函数,并且导出为Jar包,函数具体内容省略,网上有很多 将Jar包放到Jmeter lib\ext目录下面,然后在user.properties里面把路径加进去 ...

  9. 6410实现网卡(DM9000A)收发功能及ARP协议实现

    1. 网卡硬件结构(DM9000A) 网卡的实质就是MAC通过MII接口控制PHY的过程. MAC主要负责数据帧的构建.数据差错检查.传送控制等. PHY是物理接口收发器,属于物理层,当它收到MAC过 ...

  10. Add Office 365 Azure Directory into Windows Azure

    Add Office 365 Azure Directory into Windows Azure Pre-Requisite: 1.Azure Subscription to the Microso ...