티스토리 뷰
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>한글 검색 지원 폴더 트리</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
body { font-family: 'Malgun Gothic', sans-serif; padding: 20px; background: #f0f2f5; }
.tree-container { background: #fff; width: 450px; margin: 0 auto; padding: 20px; border-radius: 10px; box-shadow: 0 5px 15px rgba(0,0,0,0.1); }
.search-box input { width: 100%; padding: 12px; margin-bottom: 20px; border: 1px solid #ddd; border-radius: 5px; box-sizing: border-box; }
ul.tree, ul.tree ul { list-style: none; padding-left: 20px; }
.folder, .file { padding: 5px 8px; cursor: pointer; border-radius: 4px; display: inline-block; margin: 2px 0; }
.folder:hover, .file:hover { background: #e9ecef; }
.folder + ul { display: none; }
.folder.active + ul { display: block; }
.highlight { background-color: #ffeb3b !important; font-weight: bold; } /* 하이라이트 스타일 */
#no-result { display: none; color: #888; text-align: center; padding: 20px; }
</style>
</head>
<body>
<div class="tree-container">
<h2>📁 문서 보관함</h2>
<div class="search-box">
<input type="text" id="tree-search" placeholder="파일명(한글/영문)을 입력하세요...">
</div>
<div id="no-result">검색 결과가 없습니다.</div>
<ul class="tree" id="main-tree">
<li>
<div class="folder active">📂 개인문서</div>
<ul>
<li>
<div class="folder">📂 프로젝트_보고서</div>
<ul>
<li class="file">📄 결산보고서_최종.pdf</li>
<li class="file">📄 신규사업_기획안.docx</li>
<li class="file">📄 리액트_공부자료.txt</li>
</ul>
</li>
<li>
<div class="folder">📂 사진첩</div>
<ul>
<li class="file">📄 제주도_여행기.jpg</li>
<li class="file">📄 가족사진.png</li>
</ul>
</li>
<li class="file">📄 자기소개서_2026.hwp</li>
</ul>
</li>
<li class="file">📄 회사규정_가이드.pdf</li>
</ul>
</div>
<script>
$(document).ready(function() {
// 1. 대소문자 무시 + 한글 포함 검색 커스텀 선택자
$.expr[":"].contains = $.expr.createPseudo(function(arg) {
return function(elem) {
// trim()을 추가하여 앞뒤 공백 제거 후 비교
return $(elem).text().toLowerCase().indexOf(arg.toLowerCase().trim()) >= 0;
};
});
// 2. 폴더 열기/닫기
$(document).on('click', '.folder', function() {
$(this).next('ul').slideToggle(200);
$(this).toggleClass('active');
});
// 3. 실시간 검색 (한글 지원)
$('#tree-search').on('input', function() { // keyup보다 input 이벤트가 한글 입력에 더 정확함
const value = $(this).val();
const $treeItems = $('#main-tree li');
const $noResult = $('#no-result');
// 하이라이트 초기화
$('.folder, .file').removeClass('highlight');
if (!value.trim()) {
$treeItems.show();
$noResult.hide();
return;
}
$treeItems.hide();
// 한글 포함 검색 수행
const $matchedItems = $("#main-tree li:contains('" + value + "')");
if ($matchedItems.length > 0) {
$noResult.hide();
$matchedItems.each(function() {
$(this).show();
$(this).parents('li').show();
$(this).parents('ul').show();
$(this).parents('ul').prev('.folder').addClass('active');
// 실제 텍스트가 일치하는 자식 요소에 하이라이트
$(this).children('.folder, .file').filter(":contains('" + value + "')").addClass('highlight');
});
} else {
$noResult.show();
}
});
});
</script>
</body>
</html>
※ 해당 내용은 Google Gmini3.0에서 작성되었습니다.
'WEB > JQuery' 카테고리의 다른 글
| 상세 클릭포함 트리메뉴 (0) | 2026.01.22 |
|---|---|
| 폴더 메뉴 한글검색 전체 열기닫기 추가 (1) | 2026.01.22 |
| 폴더 트리메뉴 (0) | 2026.01.22 |
| 모바일 전체 메뉴 (0) | 2026.01.18 |
| 배너 좌우 이동 jQuery (0) | 2025.01.10 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 자바스크립트break
- jdk #jre
- sw기술자평균임금 #2025년 sw기술자 평균임금
- 파비콘 #파비콘 사이트에 적용
- 무료폰트 #무료웹폰트 #한수원한돋움 #한수원한울림 #한울림체 #한돋움체
- // 사진직: 데이터가 없으면 DEFAULT_IMG 사용 const profileSrc = (d.img && d.img !== "") ? d.img : DEFAULT_IMG;('#user-photo').attr('src'
- lg그램pro #lg그램 #노트북 #노트북추천 #lg노트북
- 바지락칼국수 #월곡동칼국수 #칼국수맛집
- css미디어쿼리 #미디어쿼리 #mediaquery
- 좋은책 #밥프록터 #부의원리
- thymeleaf
- 썬크림 #닥터지썬크림 #내돈내산 #내돈내산썬크림 #썬크림추천 #spf50썬크림 #닥터지메디유브이울트라선
- ajax
- 자바스크립트정규표현식
- iptime와이파이증폭기 #와이파이증폭기설치
- 테스크탑무선랜카드 #무선랜카드 #아이피타이무선랜카드 #a3000mini #무선랜카드추천
- 탭메뉴자바스크립트
- 쇼팬하우어 #좋은책
- 연명의료결정제도 #사전연명의료의향서 #사전연명의료의향서등록기관 #광주사전연명의료의향서
- 광주분식 #광주분식맛집 #상추튀김 #상추튀김맛집 #광주상추튀김
- 자바스크립트countiue
- jQuery #jQuery이미지슬라이드 #이미지슬라이드
- echart
- 좋은책
- 증폭기 #아이피타임증폭기
- 파비콘사이즈
- 와이파이증폭기추천 #와이파이설치
- 자바스크립트 #javascript #math
- SQL명령어 #SQL
- 정보처리기사 #정보처리기사요약 #정보처리기사요점정리
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
글 보관함

