테스트 사이트 - 개발 중인 베타 버전입니다

펄스나인님 의 [HTML5] input type="file" 에서 이미지 첨부시 바로 보여주기팁으로 채택완료

ㅐ늑대ㅐ 3년 전 조회 1,750

펄스나인님 의 ([HTML5] input type="file" 에서 이미지 첨부시 바로 보여주기) 팁으로 

무한 생성하기 만들엇는데 글쓰기 페이지에서 이미지가 바로 보이지 않습니다.

상세보기 페이지에서는정상적올 출력 되고있습니다.

https://sir.kr/g5_tip/12466

 

댓글을 작성하려면 로그인이 필요합니다.

답변 1개

애초에 제가 제이쿼리 자체를 사용하지 않는 사람이라... 순수 바닐라로 예제만 짜 봅니다.

input 는 3개인데 무한 생성이 가능합니다.

여러개 생성시는 루프문으로 돌려서 생성해도 됩니다.

input 의 id 나 name 은 본인이 원하는 걸로 주세요.

 

</p>

<p><script> 

function imgCall(img, call) {

    reader = new FileReader;

    reader.onload = function () { 

        img.src = reader.result;

    } 

    reader.readAsDataURL(call.files[0]); 

}

</script></p>

<p><input type=file accept=image/* onchange=imgCall(image_1,this)>

<img id=image_1 style=width:120px>
</p>

<p><input type=file accept=image/* onchange=imgCall(image_2,this)>

<img id=image_2 style=width:120px>
</p>

<p><input type=file accept=image/* onchange=imgCall(image_3,this)>

<img id=image_3 style=width:120px></p>

<p>

 

에를 들어 10개를 루프문으로 돌린다면 아래처럼 되겠죠.

 

</p>

<p><script> 

function imgCall(img, call) {

    reader = new FileReader;

    reader.onload = function () { 

        img.src = reader.result;

    } 

    reader.readAsDataURL(call.files[0]); 

}

limitInput = 10;

for (i = 1; i <= limitInput; i++) document.write("<input type=file accept=image/* onchange=imgCall(image_" + i + ",this)><img id=image_" + i + " style=width:120px>" + (i == limitInput ? "" : "
"));

</script></p>

<p>

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인