重写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> ...
随机推荐
- opengl入门学习
OpenGL入门学习 说起编程作图,大概还有很多人想起TC的#include <graphics.h>吧? 但是各位是否想过,那些画面绚丽的PC游戏是如何编写出来的?就靠TC那可怜的640 ...
- Win7系统安装好Axure点击运行报.NET Framework4.0未安装的解决办法
1:问题 由于工作需要,需要研究一下Axure原型设计软件的使用方式,在公司的电脑上成功安装了从同事那里拿来的Axure7.0软件,能够正确运行没有任何问题,在自己的电脑上安装的也非常顺利,不过运 ...
- super getClass()
首先看一段代码: import java.util.Date;public class Test extends Date{ public static void main(String[] args ...
- ArcGIS Engine渲染
符号化之Renderer( 渲染)体系 ArcGIS Engine9.3对GIS数据的符号化分为矢量数据渲染和栅格数据渲染两大类.接下来分别介绍FeatureRender和RasterRender. ...
- Xcode 7 调试野指针利器 Address sanitizer
Xcode 7 调试野指针利器 Address sanitizer 什么是Address Sanitizer? AddressSanitizer is a fast memory error dete ...
- robocopy 命令小结
robocopy "C:\dira" "J:\dira" /E /COPYALL /XJ /XD "C:\dira\dir1" " ...
- java中的运算符
1. 赋值运算符: (=) 2. 算术运算符: (+ ,- , * , /, %) 3. 逻辑运算符: (&& ,||, !) 4. 关系 ...
- 部署Service Manager 2012遇到的2个问题
上周装了个Service Manager 2012学习,以便完善System Center整个解决方案,在部署期间遇到2个问题,花了我不少时间解决.一.安装时提示“执行自定义操作时失败”每当到了安装的 ...
- Android工作学习第5天之Activity的传值问题
注:本文大部分为网上转载,本人只是根据工作的需要略做整合! 本章将借用一个实例,讲解如何注册并激活一个新的Activity,以及多个Activity之间如何传值. 下面是主Activity的代码: [ ...
- Android自动化学习笔记之Robotium:学习官网实例
---------------------------------------------------------------------------------------------------- ...