2012-12-06 3 views
1

간단한 html 입력 type="text"과 입력 type="file"의 기능을 수행하는 버튼을 사용하여 프로그램을 작성하고 싶습니다.<input type = "text">을 사용하여 <input type = "file">을 시뮬레이션 할 수 있습니까?

+0

당신은 숨겨진 파일 입력을하고 버튼을 눌러 파일의 OnClick을 트리거 할 수 있습니다. 작동하지만 많은 노력이 필요합니다. –

+1

내 생각에 스타일이 지정된 파일 입력을 원합니다. 이 경우 http://stackoverflow.com/questions/3226167/how-to-style-input-file-with-css3-javascript를 참조하십시오. –

답변

0

이론적으로는 해킹 할 수 있지만 ([파일] 입력 등으로 0 불투명도로 설정) 수동으로 텍스트 필드 경로를 입력하면 작동하지 않습니다 (양식이있는 파일을 보내지 않음). 불필요한 해킹이 많은 것처럼 보입니다. 무슨 이유로?

1

HTML은에서 :

<input type="file" class="file"> 
<input type="text" name="file" class="sfile"> 
<input type="submit" value="send file" name="submit"> 

CSS :

.file{ 
    visibility:hidden; # don't use display:none; because IE compability in js 
} 

jQuery를 :

$('.sfile').click(function(){ 
    $('.file').click(); 
}); 
$('.file').change(function(){ 
    $('.sfile').val($(this).val()); 
}); 
관련 문제