myForm.js
2024-10-21 02:02:15
根据控件名,重现一些特殊的表单项,生成html
var can_submit = true; function myForm($form_id, $id_value, province, city, district){
var theForm = $('#'+$form_id);
province = province || 6; //第一步,重现一些特殊的表单项(地区控件、相册控件)
$(theForm).find('div').each(function(){
var _this = $(this);
//地区列表控件
if(_this.attr('data-role') == 'position'){
Create_Position(_this, {'province':province, 'city':city, 'district':district});
} //相册上传控件
if(_this.attr('data-role') == 'album'){
Create_Album(_this, $id_value, 60, 54);
}
}); $(theForm).find('td').each(function(){
$(this).append(" <span class='tip'></span>");
}); //第二步,对特殊表单进行输入限制(必填、电话、手机、邮箱、QQ、时间)
$(theForm).find('textarea').each(function(){
var _this = $(this);
if(_this.attr('data-required') == 'true'){
_this.blur(function(){
check_required($(this));
});
}
}); $(theForm).find('input').each(function(){
var _this = $(this);
var input_type = _this.get(0).type; if(_this.attr('data-role') == 'tel'){
_this.blur(function(){
check_tel($(this));
});
} if(_this.attr('data-role') == 'phone'){
_this.blur(function(){
check_phone($(this));
});
} if(_this.attr('data-role') == 'email'){
_this.blur(function(){
check_email($(this));
});
} if(_this.attr('data-role') == 'qq'){
_this.blur(function(){
check_qq($(this));
});
} if(_this.attr('data-role') == 'timer'){
_this.attr('readonly','readonly');
_this.attr('onclick','new WdatePicker();');
} if(_this.attr('data-required') == 'true'){
_this.blur(function(){
check_required($(this));
});
}
}); //提交表单前,再次验证表单项
theForm.submit(function(){
can_submit = true;
$(theForm).find('textarea').blur();
$(theForm).find('input').blur();
//check_album(); //简介
if($('#short')) $('#short').html($("div[data-role='short']").html()); return can_submit;
});
} function check_required(_this){
var tip = _this.next('.tip');
var val = _this.val() || _this.html();
if(val == ''){
tip.html('此项为必填项!');
can_submit = false;
}else{
tip.html('');
if(_this.attr('data-role') == 'tel') return check_tel(_this); if(_this.attr('data-role') == 'phone') return check_phone(_this); if(_this.attr('data-role') == 'email') return check_email(_this); if(_this.attr('data-role') == 'qq') return check_qq(_this);
}
} function check_tel(_this){
var tip = _this.next('.tip');
var val = _this.val();
if(!is_tel(val)){
tip.html('电话格式错误!');
can_submit = false;
}else{
tip.html('');
}
} function check_phone(_this){
var tip = _this.next('.tip');
var val = _this.val();
if(!is_phone(val)){
tip.html('手机格式错误!');
can_submit = false;
}else{
tip.html('');
}
} function check_email(_this){
var tip = _this.next('.tip');
var val = _this.val();
if(!is_email(val)){
tip.html('邮箱格式错误!');
can_submit = false;
}else{
tip.html('');
}
} function check_qq(){
var tip = $(this).next('.tip');
var val = $(this).val();
if(!is_qq(val)){
tip.html('QQ格式错误!');
can_submit = false;
}else{
tip.html('');
}
} function check_album(){
if($('#show').length > 0){
var tip = $("div[data-role='album']").next('.tip');
if($('#show').html() == ''){
tip.html('请上传相册!');
can_submit = false;
}else{
tip.html('');
}
}
}
最新文章
- 转《WF编程》笔记目录
- Excel图表的基本类型与选择
- 《你必须知道的.NET》读书笔记二:小OO有大原则
- Atitit. 获取cpu占有率的 java c# .net php node.js的实现
- innodb 变量
- C#各种常用开源框架-支持开源!分享!
- WINDOWS 2008 SERVER域用户自动登陆
- (转) 制作 Clonezilla live 启动盘
- UVa 10491 Cows and Cars (概率&;广义三门问题 )
- c++,给常成员变量赋值
- UiAutomator喷射事件的源代码分析
- git 设置不需要输入密码, 去除 fetch / pull 代码每次都需要输入密码的烦恼
- R语言︱数据分组统计函数族——apply族用法与心得
- 201621123027 Week02-Java基本语法与类库
- node02
- 2159 ACM 杭电 杀怪 二维费用的背包+完全背包问题
- 查看mysql的版本号
- Node学习笔记(三)
- css实现导航切换
- stm32f10x单片机进阶--spi使用
热门文章
- Centos 开启telnet-service服务
- Redis集群的安装测试(伪分布模式 - 主从复制)
- 【打CF,学算法——二星级】Codeforces Round #313 (Div. 2) B. Gerald is into Art(水题)
- atitit.词法分析的实现token attilax总结
- jquery经常使用操作
- solr 简单搭建 数据库数据同步(待续)
- CShopDialog类
- python爬虫解析库之re模块
- ngBind {{}} ngBindTemplate
- MacBook Air 2014 安装win7