2016-04-10 36 views
0

爲標題道歉。以下是我的問題:即使在提交表單前刪除了圖像數據仍然存在

我從用戶計算機上選擇圖像文件時選擇了可以刪除所選圖像並選擇新圖像的DIY-ed圖像縮略圖。

當我點擊上傳按鈕時,它上傳了我上次選擇的相同圖像。我沒有得到它,爲什麼它也有圖像,如果我在上傳之前點擊刪除圖像按鈕?

下面是我的HTML代碼:上述

<input id="trip-photo1" type="file" class="trip-ul-photo-img" name="trip-photo[]"> 
<label for="trip-photo1"></label> 

是5輸入I爲1。

下面是我的jQuery代碼:

$(document).on('change', 'input.trip-ul-photo-img', function(){ 
     var photo_wrapper  = $(".trip-ul-photo"); //Fields wrapper 
     var photo_button  = $(".btn-trip-ul-photo"); //Add button ID 
     var reader    = new FileReader(); 
     var photo    = $(this); 
     var btn_str    = ''; 
      btn_str    += '<button type="button" class="btn btn-link btn-photo-del" role="button">X</button>'; 

     reader.onload = function (e) { 
      // get loaded data and render thumbnail. 
      var img_str  = ''; 
       img_str  += '<img class="pro-set-up-photo-preview" src="' + e.target.result + '" />' 
      photo.parent().append(img_str, btn_str); 
     }; 

     // read the image file as a data URL. 
     reader.readAsDataURL(this.files[0]); 

    }); 

    $(document).on('click', '.btn-photo-del', function(){ 
     $(this).parent(".trip-ul-photo-group").next(".trip-ul-photo-cap-wrapper").children("input, p").remove(); 
     $(this).parent(".trip-ul-photo-group").children("img, button").remove(); 
    }); 

我完全不知道是怎麼回事,因爲這也是我第一次DIY刪除所選圖像自己。

在此先感謝你們!

回答

0

問題已解決。問題在於這是每次選擇任何文件時文件輸入的默認行爲。刪除預覽圖像時,只需將數據設置爲空。

相關問題