layui的upload組件使用以及上傳阻止測試

來源:互聯網
上載者:User

標籤:cti   on()   push   xlsx   pre   multi   lld   block   remove   

背景:頁面上一個按鈕,點擊彈出上傳框,從按鈕的方法代碼開始寫:處理未選擇檔案阻止上傳;通過判斷選擇檔案的數量,顯示或隱藏上傳按鈕;

在js中定義: function  uploadFile(){

    layer.open({

        type:1,

        title:‘上傳檔案‘,

        area:[‘25%‘,‘400px‘],

        content:‘<div class="layui-form-item" style="margin-top:40px;">\

          <div class="layui-input-block">\

            <input class="layui-btn" type="button" id="chooseFIle" value="選擇檔案">\

            <span></span>\

          </div>\

        </div>\

          <div class="layui-form-item" style="margin-top:40px;">\

          <div class="layui-input-block">\

            <input class="layui-btn" type="button" id="uploadbtn" value="上傳">\

            <span></span>\

          </div>\

        </div>‘,

    btn:[‘關閉‘],

    btn1:function(idx,ele){

        layer.closeAll();

      }

  })

createUpload();

}

 

var  files ;

function createUpload(){

      $("#uploadbtn").hide();

      $("#chooseFile").next().next("span").text("");

      layui.use([‘upload‘],function(){

        var uploadInst = upload.render({

            elem:‘#chooseFile‘,

             url:‘ ‘,

              accept:‘file‘,

             auto:false,

            multiple:true,

          acceptMime:‘application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet‘,

          exts:‘xls|xlsx‘,

          size:1024000,

          number:5,

          bindAction:‘#uploadbtn‘,

          choose:function(obj){

            files = this.files = boj.pushFile();

            if(Object.keys(files).length>0){ $("#uploadbtn").show(); }

            obj.preview(function(index,file,result){

              $("#chooseFile").siblings("span").append("<div title=‘"+index+"‘>"+file.name+"&nbsp;&nbsp;<span onclick=‘deletefile(\""+index+"\")‘>&times;</span></div>")

               if(index>0) {$("#uploadbtn").show() ;}

              })

          },

        allDone:function(obj){  

            if(obj.successful){

              layer.msg(obj.total+"個檔案上傳成功!");

            }

          },

        error:function(){

          layer.alert("上傳成功!");

        }

    })

  }

}

function  deletefile(index){

  delete  files[index];

  $("#chooseFile").siblings("span").find("div[title="+index+"]").remove();

  if(!Object.keys(files).length>0){

      $("#uploadbtn").hide();

  }

 

}

 

layui的upload組件使用以及上傳阻止測試

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.