:file 은 파일을 찾는 대화상자를 띄울 수 있는 input을 찾는 선택자입니다.
원문 링크
http://api.jquery.com/file-selector/
- jQuery(':file')
예 제
input 들 중에 type 이 file 인 것을 찾아 3 픽셀 짜리 빨간 테두리를 그립니다. 그리고 찾은 개수를 표시해 줍니다.
<!DOCTYPE html>
<html>
<head>
<style>
textarea { height:45px; }
</style>
<script src="http://code.jquery.com/jquery-1.4.4.js"></script>
</head>
<body>
<form>
<input type="button" value="Input Button"/>
<input type="checkbox" />
<input type="file" />
<input type="hidden" />
<input type="image" />
<input type="password" />
<input type="radio" />
<input type="reset" />
<input type="submit" />
<input type="text" />
<select><option>Option<option/></select>
<textarea></textarea>
<button>Button</button>
</form>
<div>
</div>
<script>
var input = $("input:file").css({background:"yellow", border:"3px red solid"});
$("div").text("For this type jQuery found " + input.length + ".")
.css("color", "red");
$("form").submit(function () { return false; }); // so it won't submit
</script>
</body>
</html>미리보기
file 에 테두리 그리는 건 파이어폭스와 익스플로러가 좀 다르네요. 찾아보기 버튼까지 테두리가 그려지는건 IE 만 되는것 같습니다. 뭐 그리 중요한 내용은 아니니 개의치 마시구요.
파일 업로드 관련해서 처리할 일이 생길 때 사용하게 되겠네요.
그럼 즐프하세요.
※ 본 예제는 http://www.jquery.com 에 있는 내용임을 밝힙니다.
'프로그래밍 > jQuery' 카테고리의 다른 글
| jQuery API 정복 - ~보다 작은 요소 선택하기 : jQuery(':lt(index)') (7) | 2011.02.07 |
|---|---|
| jQuery API 정복 - ~보다 큰 요소 선택하기 : jQuery(':gt(index)') (3) | 2011.02.01 |
| jQuery API 정복 - 첫번째 요소 찾기 : jQuery(':first') (1) | 2011.01.31 |
| jQuery API 정복 - 첫째 자식(?) 찾기 : jQuery(':first-child') (3) | 2011.01.31 |
| jQuery API 정복 - 리스트 짝수,홀수 찾기 : jQuery(':even') (2) | 2011.01.28 |
| jQuery API 정복 - 인덱스로 요소 찾기 : jQuery(':eq(index)') (6) | 2011.01.28 |
| jQuery API 정복 - 사용 불가 상태 선택하기 : jQuery(':disabled') (2) | 2011.01.28 |
| jQuery API 정복 - 자식 요소 선택하기 : jQuery('ancestor descendant') (2) | 2011.01.27 |