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

심플한 파일첨부 버튼과 jquery

· 11년 전 · 2468

먼저 아래 코드를 넣어서 file type을 0으로 줄인다. 

<style>                                        

#file { width:0; height:0; }                    

</style>                                        

<script> 

$j(function(){          

    $j('#btn-upload').click(function(e){ 

        e.preventDefault();            

        $j("input:file").click();              

        var ext = $j("input:file").val().split(".").pop().toLowerCase(); 

        if($j.inArray(ext, ["gif","png","jpg","jpeg"]) == -1) { 

        alert("gif,png,jpg 파일만 업로드 할수 있습니다."); 

        return false;  

        }                              

        $j("input:file").val().toLowerCase(); 

    });                        

});                                    

</script> 

 

그리고 html내에 

<input type='file' id='file' name='file' /> 

<button id='btn-upload' class="button1 white selected" onfocus="this.blur();">사업자등록증 첨부</button> 

이렇게 해주면 깔금하게 버튼 하나로만 처리되어집니다. 

버튼에는 css로 이쁘게 처리하면 되거나 이미지로 입혀도 되겠죠? 

댓글 작성

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

로그인하기

게시글 목록

번호 제목
27925
27922
6972
19602
19601
19599
6961
30941
19597
19596
19595
19594
30939
19593
6959
6957
6953
27920
19592
19591
19590
6949
6947
20826
20823
19589
27913
27912
19588
20822
19587
19586
27887
20819
27883
19585
19584
19583
19582
19581
19580
6945
24622
19578
6938
6935
27880
20818
19575
20815
20812
20809
6932
6931
6929
19571
19570
20802
27877
20797
6923
20795
6918
6914
20789
6899
27860
6898
27856
6895
6891
6890
6881
6874
27852
6860
6857
19569
19565
19564
27844
19563
24617
19554
6854
19553
19531
6850
6848
27842
6846
6842
6839
6834
6829
6824
6820
27839
6818
19529