티스토리 뷰


자바스크립트

파일 업로드 후 화면 refresh 가 아닌 input[type=file] 안의 text만 초기화 할때 방법

input[type=file] 의 value 값을 "" 로 만들어 주면 되는데, IE는 좀 다르게 해야한다.
그래서 브라우저가 ie일때와 아닐때로 구분해서 초기화 해주어야 한다.

userAgent 로 브라우저를 확인할 수 있다. userAgent값에는 브라우저를 구분하는 고유의 값이 있다고 한다.
http://ooz.co.kr/67 참고 

input[type=text] 의 값을 초기화 해주는 방법은 ie든 다른 브라우저든 동일하게 value의 값을 " " 로 만들어 주면 되는것 같다.

1
2
3
4
5
6
7
8
9
10
var agent = navigator.userAgent.toLowerCase();
if ( (navigator.appName == 'Netscape' && navigator.userAgent.search('Trident'!= -1|| (agent.indexOf("msie"!= -1) ){
    // ie 일때 input[type=file] init.
    $("#excelFile").replaceWith( $("#excelFile").clone(true) );
    $("#parentCreateGroupFullName").val("");
else {
    //other browser 일때 input[type=file] init.
    $("#excelFile").val("");
    $("#parentCreateGroupFullName").val("");
}
cs



댓글