fileinput 外掛程式 刪除按鈕的回調操作__fileinput

來源:互聯網
上載者:User

近期項目使用fileinput這個外掛程式 主要是官方網站全部英文,個人能力有限,只能粗略解析,如有錯誤, 請提出。

官方網址:http://plugins.krajee.com/file-input   建議大家可以去看看


功能相關代碼:

$("#inputfile").fileinput({        language: 'zh', //設定語言        uploadUrl: "{:U('localhost/learnFileUpload')}", //上傳的地址        allowedFileExtensions : ['jpg', 'png','gif', 'jpeg'],//接收的檔案尾碼        initialPreview: [                 "<img src='__ROOT__"+imagePath+"' class='file-preview-image'>"             ],        showUpload: false, //是否顯示上傳按鈕        showRemove:false, // 是否顯示移除按鈕        showCaption: false,//是否顯示標題        showPreview: true,// 是否預展示圖片        maxFileCount:1,//上傳圖片最大數量        maxImageHeight:67,// 上傳圖片最大高度        initialPreviewConfig: [{               caption: 'desert.jpg',// 展示的圖片名稱               width: '120px',// 圖片高度               url: '{:U('localhost/delete')}',// 預展示圖片的刪除調取路徑               key: 100,// 可修改 情境2中會用的               extra: {id: 100} //調用刪除路徑所傳參數            }],        enctype: 'multipart/form-data',// 上傳圖片的設定        browseClass: "btn btn-primary", //按鈕樣式        uploadExtraData:{},上傳路徑的參數        previewFileIcon: "<i class='glyphicon glyphicon-king'></i>"// 按鈕樣式    }).on('fileuploaded', function(event, data, id, index) { // 上傳按鈕的回調事件if (data.response.result == 3) {                window.parent.location.href = "{:U('Login/disp')}";} else {         $("#img_path").val(data.response.fileMsg);    $('#content').html(data.response.content);}});


情境1:新增圖片,並上傳之後的刪除

$('#input-id').on('filesuccessremove', function(event, id) {    if (some_processing_function(id)) {       console.log('Uploaded thumbnail successfully removed');    } else {        return false;     }});
其中:input-id為頁面設定的input標籤的ID

filesuccessremove 為對應的名稱

此方法內可以寫具體刪除過程中的相關操作


情境2: 存在預設圖片,頁面載入完之後的刪除



這個刪除有是有對應的方法的:

方法1:刪除預先處理(刪除之前想要做什麼事)

$('#input-id').on('filepredelete', function(event, key) {    console.log('Key = ' + key);});
方法2:刪除後的處理(刪除圖片時想要做什麼事)

$('#input-id').on('filedeleted', function(event, key) {    console.log('Key = ' + key);});

對於那些未上傳的圖片刪除功能應該沒有什麼特別想做的事情,因為他不會影響到系統上任何東西,個人也就沒有特別研究


另外,目前發現一個問題,有預設圖片顯示在外掛程式中,當選擇新圖片時,會把之前的預設圖片刪除掉,這個問題暫時沒有具體研究

等有結果或者哪位知情博友有解決方案,歡迎一起分享。





聯繫我們

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