728x90
반응형
1. JSP
=> input file 선언 및 label로 input file 연동
<label for="file">
<div class="btn-upload">파일 업로드하기</div>
</label>
<input type="file" name="file" data-ax-path="file" id="file" class="form-control" width="80%">
<p id="originName" style="display : inline-block"></p>
2. CSS
=> input file을 깔끔하게 커스텀하기위한 CSS 소스
<style>
.btn-upload {
width: 130px;
height: 27px;
background: #fff;
border: 1px solid rgb(77,77,77);
border-radius: 10px;
font-weight: 500;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
&:hover {
background: rgb(77,77,77);
color: #fff;
}
}
#file {
display: none;
}
</style>
3. JS
=> 파일첨부 즉 change 시 발생하는 함수
window.onload=function(){
target=document.getElementById('file'); // file 아이디 선언
target.addEventListener('change',function(){ // change 함수
if(target.value.length){ // 파일 첨부인 상태일경우 파일명 출력
$('#originName').html(target.files[0].name);
}else{ //버튼 클릭후 취소(파일 첨부 없을 경우)할때 파일명값 안보이게
$('#originName').html("");
}
});
}
결과 화면
해당 1,2,3번을 복사붙여넣기를 사용하시면 됩니다.
728x90
반응형
'TIP)' 카테고리의 다른 글
컴맹도 익힐 수 있는 브라우저 인터넷 사용 기록(캐시) 지우는 방법 (0) | 2023.01.20 |
---|---|
컴맹도 쉽게 보는 기본 브라우저 설정하는방법 알려드립니다. (0) | 2023.01.19 |
컴퓨터활용능력 2급 독학으로 필기 합격하는 방법 (0) | 2023.01.18 |
Javascript) 시간입력(HH:MM) 시 자동으로 콜론(:) 넣는법 및 문자 작성방지 (0) | 2023.01.17 |
[TIP] 스팀 또는 에픽게임즈 무료로 다운로드 받는 꿀팁 (0) | 2022.09.19 |
댓글