我有一個問題。我想在上傳前查看我選擇的圖像的預覽。 我的代碼適用於僅1張圖片上傳。當我讓4個地方上傳照片。 4不同的4張照片,然後這不工作。我試圖更改每個上傳的ID,類。但失敗。Jquery Problem.For More that 1圖片上傳預覽
我的代碼是在這裏.. HTML
<div class="input-sec">
<label class="p-label" for="rear"><span style="font-size:15px;font-weight:bold;">Rear</span><br>
<img id="output" src="images/upload_placeholder.jpg" class="pre_img">
</label>
<input type="file" id="rear" name="rear" value="" onchange="loadFile(event)" style="color:white;">
</div>
CSS是這裏
.input-sec > input[type="file"]
{
display: none;
}
.input-sec img
{
height: 200px;
cursor: pointer;
}
jQuery是這裏。
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#frontpre').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#front").change(function(){
readURL(this);
});
我的問題是當我在頁面上只添加1張照片上傳域,它的工作原理。但是,當我嘗試添加超過1個圖像上傳字段相同,然後沒有人work.I也嘗試更改其每個上傳和JQuery的ID。但失敗了。請幫幫我。