easyui validate -- radio、checkbox 校验扩展,事件域名
事件域名: $(dom).on('click.myNameSpace',function(){ ... }),其中‘.myNameSpace’便是域名;
目前作用:$(dom).off('click.myNameSpace'),解绑指定的域名事件,其他绑定的click逻辑依旧正常。
1、extension.js:
// extend the [phone,idCard,date,time,radio,checkbox] rules
$.extend($.fn.validatebox.defaults.rules, {
phone: {
validator: function(value,param){
if(!(/^1[34578]\d{9}$/.test(value))) return false;
return true;
},
message: 'Field do not match.'
},
idCard: {
validator: function(value,param){
var reg = /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$)/;
if(reg.test(value)) return true;
return false;
},
message: 'Field do not match.'
},
date: {
validator: function(value,param){
var reg = /((^((1[8-9]\d{2})|([2-9]\d{3}))([-\/\._])(10|12|0?[13578])([-\/\._])(3[01]|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))([-\/\._])(11|0?[469])([-\/\._])(30|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))([-\/\._])(0?2)([-\/\._])(2[0-8]|1[0-9]|0?[1-9])$)|(^([2468][048]00)([-\/\._])(0?2)([-\/\._])(29)$)|(^([3579][26]00)([-\/\._])(0?2)([-\/\._])(29)$)|(^([1][89][0][48])([-\/\._])(0?2)([-\/\._])(29)$)|(^([2-9][0-9][0][48])([-\/\._])(0?2)([-\/\._])(29)$)|(^([1][89][2468][048])([-\/\._])(0?2)([-\/\._])(29)$)|(^([2-9][0-9][2468][048])([-\/\._])(0?2)([-\/\._])(29)$)|(^([1][89][13579][26])([-\/\._])(0?2)([-\/\._])(29)$)|(^([2-9][0-9][13579][26])([-\/\._])(0?2)([-\/\._])(29)$))/;
if(reg.test(value)) return true;
return false;
},
message: 'Field do not match.'
},
time: {
validator: function(value,param){
var reg = /^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-)) (20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d$/;
if(reg.test(value)){
return true;
}
return false;
},
message: 'Field do not match.'
},
radio: {
validator: function(value, param){
var input = $(param[0]),status = false,firstObj = $(input[0]),
cntObj = firstObj.parent(),initCount = cntObj.attr("initCount") || 0;
input.off('.radio').on('click.radio',function(){
$(this).focus();
try{ cntObj.tooltip('hide'); }catch(e){}
});
cntObj.off("mouseover mouseout").on("mouseover mouseout",function(event){
var bool = input.validatebox('isValid');
if(event.type == "mouseover"){
if(bool) try{ cntObj.tooltip('hide'); }catch(e){}
else try{ cntObj.tooltip('show');}catch(e){}
}else if(event.type == "mouseout") try{ cntObj.tooltip('hide'); }catch(e){}
});
if(initCount-1<0){
tipProcess(firstObj,"initCount");
initCount ++ ;
}
status = $(param[0] + ':checked').val() != undefined;
return status;
},
message: 'Please choose option for {1}.'
},
checkbox: {
validator: function (value, param) {
var inputs = $(param[0]), maxNum = param[1], checkNum = 0,status=false,
firstObj = $(inputs[0]),cntObj = firstObj.parent(),initCount = cntObj.attr("initCount") || 0;
inputs.each(function () {
if (this.checked) checkNum++;
});
inputs.off('.checkbox').on('click.checkbox',function(){
//$(this).focus();
var bool = inputs.validatebox('isValid');
if(bool) try{ cntObj.tooltip('hide'); }catch(e){}
else try{ cntObj.tooltip('show');}catch(e){}
});
cntObj.off("mouseover mouseout").on("mouseover mouseout",function(event){
var bool = inputs.validatebox('isValid');
if(event.type == "mouseover"){
if(bool) try{ cntObj.tooltip('hide'); }catch(e){}
else try{ cntObj.tooltip('show');}catch(e){}
}else if(event.type == "mouseout") try{ cntObj.tooltip('hide'); }catch(e){}
});
if(initCount-1<0){
tipProcess(firstObj,"initCount");
initCount ++ ;
}
status = checkNum > 0 ;
return status;
},
message: 'Please choose options !'
}
});
function tipProcess(firstObj,countFlag){
var dataOps = firstObj.validatebox('options'),ctn=firstObj.parent(),
tipMsg = dataOps.missingMessage || dataOps.invalidMessage || firstObj.validatebox.defaults.rules.checkbox.message;
ctn.tooltip({ position: 'right', content: '<span style="color:#000">'+tipMsg+'</span>',
onShow: function(){
$(this).tooltip('tip').css({
backgroundColor: 'rgb(255, 255, 204)',
borderColor: 'rgb(204, 153, 51)'
});
}
}).tooltip('hide');
var initCount = 0;
if(countFlag) {
initCount = ctn.attr(countFlag);
initCount = initCount - 0 + 1;
ctn.attr(countFlag,initCount);
}
}
2、html:(相关资源自行引入)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Validate Form on Submit - jQuery EasyUI Demo</title>
<link rel="stylesheet" type="text/css" href="css/metro/easyui.css">
<link rel="stylesheet" type="text/css" href="css/icon.css">
<link rel="stylesheet" type="text/css" href="css/demo.css">
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="js/extension/extension.js"></script>
<script type="text/javascript" src="js/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>
<h2>Validate Form on Submit</h2>
<p>The form does not perform validation before being submitted.</p>
<div style="margin:20px 0;"></div>
<div class="easyui-panel" title="New Topic" style="width:400px">
<div style="padding:10px 60px 20px 60px">
<form id="ff" class="easyui-form" method="post" data-options="novalidate:true">
<table cellpadding="5">
<tr>
<td>Name:</td>
<td><input class="easyui-textbox" type="text" name="name" data-options="required:true"></input></td>
</tr>
<tr>
<td>Email:</td>
<td><input class="easyui-textbox" type="text" name="email" data-options="required:true,validType:'email'"></input></td>
</tr>
<tr>
<td>Subject:</td>
<td><input class="easyui-textbox" type="text" name="subject" data-options="required:true"></input></td>
</tr>
<tr>
<td>Message:</td>
<td>
<div>
<input class="easyui-validatebox" type="radio" name="yes_no" value="1" data-options="validType:'radio[\'#ff input[name=yes_no]\', \'Yes or no\']'">Yes
<input class="easyui-validatebox" type="radio" name="yes_no" value="0">No
</div>
</td>
</tr>
<tr>
<td>Language:</td>
<td>
<div>
<input type="checkbox" name="cb1" class="easyui-validatebox" value="1" validType="checkbox['#ff input[name=cb1]']"/>ck1
<input type="checkbox" name="cb1" class="easyui-validatebox" value="2"/>ck2
<input type="checkbox" name="cb1" class="easyui-validatebox" value="3" />ck3
<input type="checkbox" name="cb1" class="easyui-validatebox" value="4" />ck4
</div>
</td>
</tr>
</table>
</form>
<div style="text-align:center;padding:5px">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()">Submit</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()">Clear</a>
</div>
</div> </div>
<script>
function submitForm(){
$('#ff').form('submit',{
onSubmit:function(){
return $(this).form('enableValidation').form('validate');
}
});
}
function clearForm(){
$('#ff').form('clear');
} </script>
</body>
</html>
easyui validate -- radio、checkbox 校验扩展,事件域名的更多相关文章
- JQuery触发radio或checkbox的change事件
在JQuery中,当给radio或checkbox添加一个change事件时,如果它的值发生变化就会触发change事件;本文将详细介绍如何利用JQuery触发Checkbox的change事件需要了 ...
- radio与checkbox的选中事件
<一>判断checkbox的选中事件 var result=$(this).find("input[type='checkbox']").prop("chec ...
- bootstrap+jQuery.validate表单校验
谈谈表单校验 这大概是一种惯例,学习前台后台最开始接触的业务都是用户注册和登录.现在社会坚持以人为本的理念,在网站开发过程同样如此.User是我们面对较多的对象,也是较核心的对象.最开始的用户注册和登 ...
- jQuery.validate表单校验+bootstrap
谈谈表单校验 这大概是一种惯例,学习前台后台最开始接触的业务都是用户注册和登录.现在社会坚持以人为本的理念,在网站开发过程同样如此.User是我们面对较多的对象,也是较核心的对象.最开始的用户注册和登 ...
- SQL Server 扩展事件(Extented Events)从入门到进阶(4)——扩展事件引擎——基本概念
本文属于 SQL Server 扩展事件(Extented Events)从入门到进阶 系列 在第一二节中,我们创建了一些简单的.类似典型SQL Trace的扩展事件会话.在此过程中,介绍了很多扩展事 ...
- 微信小程序 - radio/checkbox自定义组件
更新 2019-01-26:首次发布 2019-01-27:增加默认取值选中radio/checkbox,checkbox需在onload取值 2019-01-28:增加radio取值不存在红色提示和 ...
- SQLSERVER2012里的扩展事件初尝试(上)
SQLSERVER2012里的扩展事件初尝试(上) SQLSERVER2012里的扩展事件初尝试(下) 周未看了这两篇文章: 扩展事件在Denali CTP3里的新UI(一) 扩展事件在Denali ...
- Solon详解(六)- Solon的校验扩展框架使用与扩展
Solon详解系列文章: Solon详解(一)- 快速入门 Solon详解(二)- Solon的核心 Solon详解(三)- Solon的web开发 Solon详解(四)- Solon的事务传播机制 ...
- 利用扩展事件进行调优和Troubleshooting PPT分享
本篇主题是我在2015年中国数据库大会(DTCC)上的分享,扩展事件从2008版本出来到现在已经有6-7年,国内却很少有相关资料和使用,现在分享一下PPT,希望对大家有所帮助. 可 ...
随机推荐
- sqlserver 查看当前连接数
参考 https://www.cnblogs.com/lumnm/archive/2009/08/29/1556349.html SELECT * FROM[Master].[dbo].[SYSPRO ...
- hibernate 中,出现了错误 "node to traverse cannot be null!" 如何改正
这个错误基本上是因为hql语句写错了而造成的, 返回找hql输出一下发现, hql语句中间少了几个空格, 写成了String hql = "from"+className+&quo ...
- hadoop深入简出(二)
1.上传文件 Hadoop fs -put hello.txt / 2.查看上传的文件 hadoop fs -ls / hadoop fs -text /hello.txt 两个命令都可以 3.创建文 ...
- unity实现3D物体上的事件监听处理
想要在3D物体上实现全套事件监听处理: OnMouse系列 OnTrigger系列 OnPointer系列 OnDrag系列 1.在相机中添加Physics Raycaster组件 2.3D物体上 ...
- vue params和query传参区别
参考地址:https://blog.csdn.net/bluefish_flying/article/details/81011230 router.js中 路由设置这里, 当你使用params方法传 ...
- CodeForces - 55D(数位dp,离散化)
题目来源:http://codeforces.com/problemset/problem/55/D Volodya is an odd boy and his taste is strange as ...
- Django的具体操作(二)
今日内容:用户登录以及分页的实现 views.py # 登录动作 def login_action(request): # 必须继承request if request.method == 'POST ...
- Day 07 文件的相关操作
文件初始: 文件的三要素: path:文件的路径 mode:r w r+ w+ a encoding: 编码方式 # 打开一个文件的方法 f1 = open('e:\echo.txt', encodi ...
- git ----(2)
Git使用40个16进制字符的SHA-1 Hash来唯一标识对象 Git的四种基本对象类型,组成了Git更高级的数据结构: blobs: 每个blob代表一个(版本的)文件,blob只包含文 ...
- Spring事务<tx:annotation-driven/>的理解
在使用Spring的时候,配置文件中我们经常看到 annotation-driven 这样的注解,其含义就是支持注解,一般根据前缀 tx.mvc 等也能很直白的理解出来分别的作用. <tx:an ...