jquery fileupload plugin

來源:互聯網
上載者:User

標籤:change   code   cancel   ror   按鈕   alert   描述   擷取檔案   外掛程式   

demo :https://blueimp.github.io/jQuery-File-Upload/

github:https://github.com/blueimp/jQuery-File-Upload

api:https://github.com/blueimp/jQuery-File-Upload/wiki/API

 

最近總是遇到上傳問題,一直使用的都是jquery-fileupload這款外掛程式, 有詳細的Api文檔,具體用法就不做詳細描述了。

只說填過的坑。

(1)自動 上傳 與非自動,使用者觸發,
        

$(‘#fileupload‘).fileupload({    add: function (e, data) {     //綁定觸發按鈕事件      $.("#okBtn").on("click",function(){         data.submit();           })    }});

 

(2)IE8,9圖片預覽問題

         以前的部落格裡寫過對這個的封裝方法,大家可以翻一下瞅瞅;

(3)IE8 input框使用者點擊事件
            “input=file”,擷取檔案時,在IE8下無法通過某個按鈕click事件間接觸發input=file的change事件,

            如果設計裡這麼要求了,可以用樣式解決,將input透明 置於上層,放原按鈕位置之上

(4)選擇之後,事件取消 abort

var jqXHR = $(‘#fileupload‘).fileupload(‘send‘, {files: filesList})    .error(function (jqXHR, textStatus, errorThrown) {        if (errorThrown === ‘abort‘) {            alert(‘File Upload has been canceled‘);        }    });$(‘button.cancel‘).click(function (e) {    jqXHR.abort();});

(5)多檔案一次一條請求上傳

<form >    <input name="file1[]" type="file" multiple />    <br />        <input name="file2[]" type="file" multiple />    <br />        <input name="file3[]" type="file" multiple />    <br />     <button>send by fileupload send api</button></form>
$(document).ready(function(){    var filesList = [],        paramNames = [],        elem = $("form");    file_upload = elem.fileupload({        formData:{extra:1},        autoUpload: false,        fileInput: $("input:file"),    }).on("fileuploadadd", function(e, data){        filesList.push(data.files[0]);        paramNames.push(e.delegatedEvent.target.name);    });    $("button").click(function(e){        e.preventDefault();        file_upload.fileupload(‘send‘, {files:filesList, paramName: paramNames});    })})

 

jquery fileupload plugin

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.