根据控件名,重现一些特殊的表单项,生成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. Python-多线程学习总结

    我们在做软件开发的时候很多要用到多线程技术.例如如果做一个下载软件象flashget就要用到.象在线视频工具realplayer也要用到因为要同时下载media stream还要播放.其实例子是很多的 ...

  2. C# 非顶端窗口截图 - 用于查找指定窗口并截图

    原文地址:http://blog.csdn.net/u013096568/article/details/53400389 panel上可以通过DrawToBitmap截图,不管是否在屏幕外是否有遮挡 ...

  3. IO多路复用之epoll

    1.基本知识 epoll是在2.6内核中提出的,是之前的select和poll的增强版本.相对于select和poll来说,epoll更加灵活,没有描述符限制.epoll使用一个文件描述符管理多个描述 ...

  4. hook NtReadVirtualMemory干扰杀软扫描

      信息来源:邪恶八进制信息安全团队(www.eviloctal.com)文章作者:asm(http://www.sbasm.cn) 写了个对抗扫描的东西,跟大家分享!技术含量不高,大牛飘过.一直以来 ...

  5. SIM800L透传模式配置

    UART1_SendString("AT+CIPCLOSE=1"); //关闭连接 delay_ms(100); Second_AT_Command("AT+CIPSHU ...

  6. 各种Map的区别,想在Map放入自定义顺序的键值对

    今天做统计时需要对X轴的地区按照地区代码(areaCode)进行排序,由于在构建XMLData使用的map来进行数据统计的,所以在统计过程中就需要对map进行排序. 一.简单介绍Map 在讲解Map排 ...

  7. servlet响应解析

    response对象可以设置一些响应信息 1)设置状态码 response.setStatus(int) 2)设置响应头信息.定时刷新或者间隔 n 秒后跳转 response.setHeader(&q ...

  8. C# FTP操作类可用

    public class FtpClient { #region 构造函数 /// <summary> /// 创建FTP工具 /// <para> /// 默认不使用SSL, ...

  9. dataGridViewX操作

    private void dataGridView1_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e) { ...

  10. ENGINE_API CXSroll

    #ifndef __XSROLL_H__ #define __XSROLL_H__ #include "CocoHead.h" #include "XWindow.h&q ...