根据控件名,重现一些特殊的表单项,生成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. postgresql一般crud存储过程参考[转]

    http://blog.csdn.net/cdnight/article/details/18082255 这里是一份经过再三调试测试而成功的postgres数据库单表crud存储过程,请注意,对于多 ...

  2. cordova添加Splash

    最新版本的cordova添加Splash只需要改写config.xml 官方文档地址为:http://cordova.apache.org/docs/en/4.0.0/config_ref_image ...

  3. mysql innodb的重要组件

    innodb包涵如下几个组件 一.innodb_buffer_pool: 1 它主要用来缓存数据与索引(准确的讲由于innodb中的表是由聚集索引组织的,所以数据只不是过主键这个索引的叶子结点). 二 ...

  4. CentOS 6.4 yum安装chrome

    CentOS 6.4安装chrome浏览器 vim /etc/yum.repos.d/CentOS-Base.repo 根据你的系统增加一个节点 32-bit [google] name=Google ...

  5. TRIZ系列-创新原理-17-转变到新维度原理

    转变到新维度原理的表述例如以下:1)把物体的动作.布局从一维变成二维.二维变成三维,以此类推     假设物体在本维度上的运动或者定位非常困难.就能够过渡到更高维度上,一般路线为:直线运动--> ...

  6. Python中模拟C# Linq的一些操作

    闲来无事时积累的一些Linq函数,有时间就更新. 需要注意python版本如果低于3.0不支持lambda,只能单独写函数传参,比较麻烦 1.FirstOrDefault: def FirstOrDe ...

  7. 执行git命令出现 xcrun: error:

    xcrun: error: active developer path ("/Applications/Xcode.app/Contents/Developer") does no ...

  8. Oracle 11g安装图文攻略

    一.Oracle 下载 注意Oracle分成两个文件,下载完后,将两个文件解压到同一目录下即可. 路径名称中,最好不要出现中文,也不要出现空格等不规则字符. 官方下地址: http://www.ora ...

  9. AndroidStudio添加Android源码

    找了半天没找到,还是用google好啊!修改如下,打开如下的build.gradle,修改compileSdkVersion 为你下载的源码版本号. Open your sdk manager fro ...

  10. js、jquery遍历对象

    js遍历对象: var obj = {a:1,b:2,c:3} for(var s in obj){ alert(obj[s]); } jquery遍历对象: var obj = {a:1,b:2,c ...