zoukankan      html  css  js  c++  java
  • 图片上传验证

     {
            colspan : 6,
            120,
            xtype: 'filefield',
            name: 'photo',
            120,
            buttonText: '选择文件',
            buttonOnly : true,    
            
            validator:function(value){
                                
                                var array=value.split('.');
                                if(array[array.length-1]=='jpg' || array[array.length-1]=='JPG'||array[array.length-1]=='bmp'){
                                    if(this.fileInputEl.dom.files[0].size>20971){
                    
                            
                    
                                        return '文件不能超过20k';
                                    }
                                                    return true;
                                    
                                }else{
                                
                                    
                                    
                                    return '文件格式不正确';
                                }
                            
                            
                            },
                listeners:{
                            
                             change:{fn:'changeImgSrc'}
                            
                 }                    
    },

        changeImgSrc:function(me,o,e){
            
                var array=o.split('.');
                
                console.log(me.fileInputEl.dom.files[0]);
                if(array[array.length-1]=='jpg' || array[array.length-1]=='JPG'||array[array.length-1]=='bmp'){
                    if(me.fileInputEl.dom.files[0].size>50971){
                    
                            
                        console.log(this);
                        alert('文件不能超过50k');
                        this.lookupReference("filefileld").setValue("");
                        
                    }else{
                    
                    
                        this.lookupReference('imageHead').getEl().dom.src=window.URL.createObjectURL(me.fileInputEl.dom.files[0]);
                        
                        this.lookupReference('imageHead').show();
                    
                    }
                                
                                    
                                    
                }else{
                                
                                    
                        alert('文件格式不正确');
                }
                
                
        },

  • 相关阅读:
    git config 命令各参数有何区别
    Git 初始化
    Linux 安装 Git
    在Mac OS 上安装 Git
    maven 部署到远程仓库(私服)
    Git与SVN的区别
    windows挂载NFS文件系统无法访问/修改文件解决
    mysql5.7写入数据时间相差13/14小时解决
    mysql配置文件不生效解决
    springdata jpa mysql5.7写入中文乱码解决
  • 原文地址:https://www.cnblogs.com/tian114527375/p/5790592.html
Copyright © 2011-2022 走看看