根据控件名,重现一些特殊的表单项,生成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("&nbsp;&nbsp;&nbsp;<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('');
}
}
}

myForm.js的更多相关文章

  1. 很强大的HTML+CSS+JS面试题(附带答案)

    一.单项选择(165题) 1.HTML是什么意思? A)高级文本语言 B)超文本标记语言 C)扩展标记语言 D)图形化标记语言 2.浏览器针对于HTML文档起到了什么作用? A)浏览器用于创建HTML ...

  2. 表单验证插件之jquery.validate.js

    提到表单验证的插件,第一个想到的就是jquery.validate.js,所以小生想在这里稍微详细地说一下这款插件的具体使用方法,便于理解,我直接附上整段demo的代码(没怎么调样式,主要是看js): ...

  3. CI模板加载css和js

    1.需求 ci无法加载css和js文件. 2.解决 删除..htaccess文件. 在config目录下配置base_url,并传给页面 $base_url = $this->config-&g ...

  4. JS技巧

    2016-08-09 200多个js技巧代码(Down) word下载 200多个js技巧代码 目录 1.文本框焦点问题... 6 2.网页按钮的特殊颜色... 6 3.鼠标移入移出时颜色变化... ...

  5. js正则表达式语法

    1. 正则表达式规则 1.1 普通字符 字母.数字.汉字.下划线.以及后边章节中没有特殊定义的标点符号,都是"普通字符".表达式中的普通字符,在匹配一个字符串的时候,匹配与之相同的 ...

  6. 学习zepto.js(对象方法)[5]

    继续说. clone: 该方法不接收任何参数,会返回对象中的所有元素集合,但不会对象绑定的事件. var $temp = $("div").clone(); //并不接收任何参数. ...

  7. JS复习--更新结束

    js复习-01---03 一 JS简介 1,文档对象模型 2,浏览器对象模型 二 在HTML中使用JS 1,在html中使用<script></script>标签 2,引入外部 ...

  8. jquery.validate.js插件使用

    jQuery验证控件jquery.validate.js使用说明+中文API 官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-valid ...

  9. JS问题汇总

    1.Q:$(this)在js中失效,无法获取当前元素 A​:function()在被调用时this是指向window的,如果要想指向被点击的元素,一般是将this作为参数传入,例如: <div ...

随机推荐

  1. TFS创建登录用户并连接TFS

    简单使用 1.创建TFS组(Windows的组) 2.在“TFS管理控制台”中设置“组成员资格” 3.给“Team Foundation Administrators”组设置“属性” 4.给“Team ...

  2. Linux命令-目录处理命令:rm

    rm grub.conf 删除当前目录中grub.conf文件 (最好是先复制一个文件,然后再删除,这样保险) rm -f grub.conf 强制删除当前目录中的grub.conf文件 (不需要确认 ...

  3. HDU 4946 Area of Mushroom 共线凸包

    题意是在二维平面上 给定n个人 每一个人的坐标和移动速度v 若对于某个点,仅仅有 x 能最先到达(即没有人能比x先到这个点或者同一时候到这个点) 则这个点称作被x占有 若有人能占有无穷大的面积 则输出 ...

  4. C# BackgroundWorker的Bug???

    废话不多说,上代码: public partial class Form1 : Form { BackgroundWorker _bgWorker; int count; public Form1() ...

  5. xdebug安装教程

    自动分析应该下载的文件: http://xdebug.org/wizard.php

  6. [svc]salt-grains

    用途 1,匹配客户端 2,配置文件里使用 3,资产管理 定义grains方法1: 方法2:

  7. EditText禁止输空格

    1.EditText禁止输空格 editText.setFilters(new InputFilter[]{filter}); private InputFilter filter=new Input ...

  8. MySQL中的Multi-Range Read优化

    MySQL 5.6开始支持Multi-Range Read(MRR)优化.目的是味儿减少磁盘的随机访问,并且将随机访问转化为较为顺序的数据访问,这对IO-bound类型的SQL查询语句可带来性能极大的 ...

  9. 记一次线上MySQL数据库死锁问题

            最近线上项目报了一个MySQL死锁(DealLock)错误,虽说对业务上是没有什么影响的,由于自己对数据库锁这块了解不是很多,之前也没怎么的在线上碰到过.这次刚好遇到了,便在此记录一下 ...

  10. Fast RDP Brute暴力破解3389口令

    http://www.tuicool.com/articles/b67rQfr 下载地址:https://www.rekings.com/fast-rdp-brute-gui-v2-0/