zoukankan      html  css  js  c++  java
  • js实现简单的文件上传

    文件下载:https://www.cnblogs.com/xiaomili/p/10521160.html 

    html:

    <form name="form1" id="form1">  
         <input type="text" name="name" value="fdipzone">  
         <input type="text" name="gender" value="male">  
         <input type="file" />文件上传
        <button type="button">上传文件</button>    
    </form> 

    js:

            /**
                 * 文件上传
                 */
                uploadFile(dom,upload,fn=false){
                  const self = this;
                  $(dom).on('change',function(){
                    let _index = $(this).index();// 表单索引0,1(多个表单)
                    let fd = new FormData();// // FormData 对象
                    let {length} = $(this).get(_index).files;
    
                    if(length > 0){
                      for(let index of [...new Set($(this).get(_index).files)].keys()){
                        fd.append("file",  $(this).get(_index).files[index]);// 添加参数
                      }
                    }
    
                    let $http = self.$util.Ajax;
                    let url = `${upload}`;// 上传地址
                    let data = fd;
    
                    $http.post(url, data, (res) => {// 自己包装的ajax
                      if (res.status == 0) {
                        self.$util.MessageUtil.info('上传成功!');
                      }else{
                        self.$util.MessageUtil.error('上传失败!');
                      }
                    },'json',true,false);
    
                  });
                },
  • 相关阅读:
    数据库(六)
    数据库(五)
    数据库(四)
    数据库(三)
    数据库(二)
    数据库
    函数 枚举和递归
    数据类型(四) 集合
    数据库基础
    特殊集合 结构体
  • 原文地址:https://www.cnblogs.com/xiaomili/p/10531998.html
Copyright © 2011-2022 走看看