重写form 表单的验证信息
(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 表单的验证信息的更多相关文章
- 深入了解Element Form表单动态验证问题 转载
随风丶逆风 2020-04-03 15:36:41 2208 收藏 3 分类专栏: Vue 随笔 文章标签: 动态验证 el-form elementUI 表单验证 版权 在上一篇<vue ...
- form 表单jquery验证插件使用
第一部分:表单样式 <form action="#" method="post" id="regist"> <tabl ...
- Vue Element Form表单时间验证控件使用
如果直接使用Element做时间选择器,其规则(rules)不添加type:'date',会提示类型错误,处理这个需要规范值的类型为date. 时间格式化过滤器 import Vue from 'vu ...
- a链接易混淆与form表单简易验证用法详解
链接可以说遍布互联网,比如你想提供一个可以跳转到百度首页的链接给网友,那么代码如下: <a href="http://www.baidu.com">百度一下,你就知道& ...
- form表单点击后验证
function check(){ var customertype = document.getElementById("customertype"); //alert(cust ...
- element-ui Form表单验证
element-ui Form表单验证规则全解 element的form表单非常好用,自带了验证规则,用起来很方便,官网给的案例对于一些普通场景完全没问题,不过一些复杂场景的验证还得自己多看文档摸索, ...
- Django学习笔记(6)——Form表单
知识储备:HTML表单form学习 表单,在前端页面中属于最常见的一个东西了.基本上网站信息的提交都用到了表单,所以下面来学习Django中优雅的表单系统:Form 表单的主要作用是在网页上提供一个图 ...
- js阻止form表单重复提交
防止表单重复提交的方法总体来说有两种,一种是在js中阻止重复提交:另一种是在后台利用token令牌实现,大致思路是生成一个随机码放到session和form表单的隐藏输入框中,提交表单时两者对比,表单 ...
- java:JavaScript2:(setTimeout定时器,history.go()前进/后退,navigator.userAgent判断浏览器,location.href,五种方法获取标签属性,setAttribute,innerHTML,三种方法获取form表单信息,JS表单验证,DOM对象,form表单操作)
1.open,setTimeout,setInterval,clearInterval,clearTimeout <!DOCTYPE> <html> <head> ...
随机推荐
- codeforces 练习
codeforces 627 D. Preorder Test 二分 + 树dp 做logn次树dp codeforces 578D.LCS Again 给出一个字符串str,长度n<=10^6 ...
- js运动框架之掉落的扑克牌(重心、弹起效果)
玩过电脑自带纸牌游戏的同志们应该都知道,游戏过关后扑克牌会依次从上空掉落,落下后又弹起,直至"滚出"屏幕. 效果如图: 这个案例的具体效果就是:点击开始运动,纸牌会从右上角掉 ...
- C#位操作(转)
在C#中可以对整型运算对象按位进行逻辑运算.按位进行逻辑运算的意义是:依次取被运算对象的每个位,进行逻辑运算,每个位的逻辑运算结果是结果值的每个位.C#支持的位逻辑运算符如表2.9所示. 算符号 意义 ...
- 使用compass编译sass
1.初始化项目 compass create test(项目名称),会在当前目录下创建test子目录,test的子目录下有config.gb文件,sass和stylesheets文件夹. 2.编写sa ...
- expdp远程导出数据
环境: 源: os:windows db:11.2.0.1 ip:192.168.213.129 sid:orcl 远程机导出: os:centos 6.5 x64 db:11.2.0.4 ip:19 ...
- 浅谈oracle10G spfile与pfile(转)
转自:http://blog.csdn.net/onebigday/article/details/6108348,http://www.linuxidc.com/Linux/2012-11/7371 ...
- 《疯狂Java讲义》(四)---- 面向对象&基于对象
"基于对象"也使用了对象,但是无法利用现有的对象模板产生新的对象类型,继而产生新的对象,也就是说,"基于对象"没有继承的特点,而多态更需要继承,所以" ...
- hive内部表、外部表、分区表、视图
1.Table 内部表 1).与数据库中的Table在概念上是类似的 2).每一个Table在Hive中都有一个相应的目录存储数据 3).所有的Table数据(不包括 External Table) ...
- JS传参中文乱码
在传参的时候给中文参数加上两个encodeURI即可,类似这样: encodeURI(encodeURI(balanceUnit)) 写法二 escape(encodeURI(tmplItem.hyz ...
- LR12.53—第3课:重播Vuser脚本
第3课:重播Vuser脚本 在前面的教训,你记录了一组典型的用户行为,并准备重播脚本. 重播脚本之前,您可以配置脚本的运行时设置,它定义了Vuser的行为. 注:记录与基于Web的协议的地方WebTo ...