根据控件名,重现一些特殊的表单项,生成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. eval函数处理JSON数据需要加括号

    在将服务器端构建好的JSON数据转化为可用的JavaScript对象时常常使用eval函数.如下: var dataJson = eval('(' + data + ')'); 在转化的时候需要将JS ...

  2. zend studio 10安装+破解+汉化

    http://pan.baidu.com/share/link?shareid=1857675714&uk=3325301372 在线安装汉化包:http://309614533.blog.1 ...

  3. 动态修改Spring定时器

    spring 的Quartz定时器的功能非常强大,可以在特定的年月日小时分秒的时间点触发时间,完成事件的调度,就像windows中得计划任务一样.下面看一个典型的Quartz定时器的实现:   1.首 ...

  4. 学习XML(添加一个子节点) 摘录

    这里介绍添加XML节点的方法. 首先定义XML文件:(bookstore.xml) <?xml version="1.0" encoding="utf-8" ...

  5. Node Redis 小试

    Redis 是一个高性能的 key-value 数据库,为了保证效率,数据都是缓存在内存中,在执行频繁而又复杂的数据库查询条件时,可以使用 Redis 缓存一份查询结果,以提升应用性能. 背景 如果一 ...

  6. Django模版中的过滤器详细解析 Django filter大全

    就象本章前面提到的一样,模板过滤器是在变量被显示前修改它的值的一个简单方法. 过滤器看起来是这样的: {{ name|lower }} 显示的内容是变量 {{ name }} 被过滤器 lower 处 ...

  7. windows下MongoDB的安装,配置与开机自启动

    关于简介不多说百度去吧少年.. MongoDB详细安装: 1.进入官网,点击DOWNLOAD MONGODB,下载所需要的版本.. 我这里把下载的文件放在d\MongoDB文件夹下,点击下载的官方镜像 ...

  8. ctags高级用法

    1.ctags -R 有个问题,成员变量没有包含在里面.所以自动完成对象的成员时没有提示.解决办法:$ctags -R --fields=+iaS --extra=+q *–fields=[+|-]f ...

  9. MySQL存储过程使用实例详解

    本文介绍关于在MySQL存储过程游标使用实例,包括简单游标使用与游标循环跳出等方法 例1.一个简单存储过程游标实例 DROP PROCEDURE IF EXISTS getUserInfo $$CRE ...

  10. (oneway void) release中oneway的意思

    oneway is used with the distributed objects API, which allows use of objective-c objects between dif ...