zoukankan      html  css  js  c++  java
  • myForm.js

    根据控件名,重现一些特殊的表单项,生成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('');
            }
        }
    }
  • 相关阅读:
    FastAPI(60)- 针对 WebSocket 进行单元测试
    FastAPI(59)- 详解使用 OAuth2PasswordBearer + JWT 认证
    FastAPI(58)- 使用 OAuth2PasswordBearer 的简单栗子
    FastAPI(57)- 安全相关的概念
    FastAPI(56)- 使用 Websocket 打造一个迷你聊天室
    FastAPI(55)- Events: startup
    FastAPI(54)- 详解 Request 请求对象
    FastAPI(53)- Response Headers 响应设置 Headers
    FastAPI(52)- Response Cookies 响应设置 Cookies
    FastAPI(51)- 自定义响应之 StreamingResponse、FileResponse
  • 原文地址:https://www.cnblogs.com/tujia/p/6118929.html
Copyright © 2011-2022 走看看