2016-09-22 100 views
1

我有一個帶有fileupload的窗體。如何清除使用jQuery選擇圖像的img佔位符

<input class="file" type="file" name="files[]"> 

我curently克隆輸入,但如果一個文件被choosen也克隆已選定filinput,有沒有辦法清除所選圖像?

腳本:$('.fieldset-content_doc').first().clone().appendTo('.fieldset-clone_doc').find('.file').reset();

字段集-content_doc:持有formvalues

+0

你是如何克隆呢? – haim770

+0

它也發生在https://jsfiddle.net/7z1eu4ab/嗎? – haim770

+0

是的,接縫它。 – sdfgg45

回答

1

顯然這個問題只能在Firefox上重現。但是,你可以簡單地設置元素到nullvalue屬性:

$('.fieldset-content_doc') 
    .first() 
    .clone() 
    .appendTo('.fieldset-clone_doc') 
    .find('.file') 
    .each(function() { this.value = null; }); 

Fiddle

0

您不能使用reset()方法,如果字段不是裏面<form>。 您可以通過將元素包裝到表單中來重置它,然後展開來清除輸入。

function resetFormElement(e) { 
    e.wrap('<form>').closest('form').get(0).reset(); 
    e.unwrap(); 

    // Prevent form submission 
    e.stopPropagation(); 
    e.preventDefault(); 
} 

參見:https://stackoverflow.com/a/13351234/3581321

0

在你的腳本,而不是reset()可以使用val('')。像這樣

$('.fieldset-content_doc').first().clone().appendTo('.fieldset-clone_doc').find('.file').val('');