0
我有以下代碼:jQuery的插入文件輸入的onchange錯誤
HTML
<label>File Upload: </label>
<input type="file" name="file[]" />
jQuery的
$('#property_enquiry input[type=file]').change(function() {
$('<input type="file" name="file[]">').insertAfter("input[type=file]");
});
我希望發生的是,一旦第一個文件是添加一個新的輸入被添加到當前的下面。上面的代碼在添加第一個文件來創建第二個輸入時起作用,但是當添加第二個文件時沒有創建第三個輸入。
謝謝,剛剛嘗試過。它似乎是以倍數完成的,一旦第一個輸入被填充,它就會添加第二個輸入。當添加第二個文件到輸入時,它會複製前兩個輸入(包括文件名),並在其底部添加一個新字段。 – lethalMango
使用'.insertAfter(「input [type = file]:last」);' – arnaud576875
賓果,就像一個魅力。非常感謝,節省了我幾個小時的麻煩! :) – lethalMango