1
자바 스크립트로 이미지 미리보기 인라인 HTML 전에 파일 업로드를 코딩했습니다. 하지만 부트 스트랩 모달 팝업 상자에 이미지 미리보기를 표시해야합니다. HTML 인라인이 아닙니다. 코드를 어떻게 변경해야합니까? 여기 내 코드가있다.부트 스트랩 모달 박스에서 이미지 미리보기를 표시하는 방법?
<script>
$(document).on('click','.close',function(){
$(this).parents('span').remove();
})
document.getElementById("uploadBtn").onchange = function() {
document.getElementById("uploadFile").value = this.value;
};
document.getElementById('uploadBtn').onchange = uploadOnChange;
function uploadOnChange() {
var filename = this.value;
var lastIndex = filename.lastIndexOf("\\");
if (lastIndex >= 0) {
filename = filename.substring(lastIndex + 1);
}
var files = $('#uploadBtn')[0].files;
for (var i = 0; i < files.length; i++) {
(function(i) {
$("#upload_prev").append('<div><span><br><div class="col-md-10"><span class="uploadFiles">' + '<a href="" data-toggle="modal" data-target="#myModal">' + files[i].name + '</a>' + '</span><br><label class="filelink"></label></div><div class="col-md-2"><p class="close" style="font-size: 13pt;">削除</p><br></div></span></div>');
$("#upload_prev a:contains(" + files[i].name + ")")
.on("click", function(e) {
e.preventDefault();
var close = $(this).closest("div")
.find(".filelink");
if (!$(this).closest("div")
.find("img").length)
close
.after(
$('<img>', {
src: URL.createObjectURL(files[i])
}).width('50%').height('50%')
)
else
close.siblings("img").toggle()
})
})(i);
}
document.getElementById('filename').value = filename;
}
내 대답이 맞으면 내 대답을 수락 할 수 있습니다. –
이 질문은 이미 게시되었습니다. 게시하기 전에 답변을 검색하십시오. this http://stackoverflow.com/a/25023822/6448640 –