티스토리 뷰
<!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>
<script src="https://unpkg.com/hangul-js"></script>
<style>
body { font-family: 'Malgun Gothic', sans-serif; padding: 20px; background: #f4f7f6; }
.tree-container { background: #fff; width: 480px; margin: 0 auto; padding: 30px; border-radius: 15px; box-shadow: 0 10px 30px rgba(0,0,0,0.08); }
/* 버튼 스타일 */
.control-btns { display: flex; gap: 5px; margin-bottom: 10px; justify-content: flex-end; }
.btn { padding: 6px 12px; font-size: 12px; cursor: pointer; border: 1px solid #ddd; background: #fff; border-radius: 4px; transition: 0.2s; }
.btn:hover { background: #f8f9fa; border-color: #bbb; }
.search-box input { width: 100%; padding: 15px; margin-bottom: 20px; border: 2px solid #e0e0e0; border-radius: 10px; box-sizing: border-box; outline: none; }
.search-box input:focus { border-color: #3498db; }
ul.tree, ul.tree ul { list-style: none; padding-left: 25px; }
.folder, .file { padding: 6px 12px; cursor: pointer; border-radius: 6px; display: inline-block; margin: 2px 0; font-size: 14px; }
.folder:hover, .file:hover { background: #ecf0f1; }
/* 초기 상태: 전체 열림을 위해 기본 display를 block으로 설정하거나 JS로 제어 */
.folder + ul { display: block; }
.highlight { background-color: #ffeaa7 !important; color: #d63031; font-weight: bold; }
#no-result { display: none; color: #95a5a6; text-align: center; padding: 20px; }
</style>
</head>
<body>
<div class="tree-container">
<h2>📂 문서 탐색기</h2>
<div class="control-btns">
<button id="btn-expand" class="btn">전체 열기 +</button>
<button id="btn-collapse" class="btn">전체 닫기 -</button>
</div>
<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 active">📂 기획단계</div>
<ul>
<li class="file">📄 결산보고서.pdf</li>
<li class="file">📄 사업계획서_v2.docx</li>
</ul>
</li>
<li>
<div class="folder active">📂 결과물</div>
<ul>
<li class="file">📄 최종디자인.jpg</li>
</ul>
</li>
</ul>
</li>
<li class="file">📄 업무가이드라인.pdf</li>
</ul>
</div>
<script>
$(document).ready(function() {
// [1] 초기 설정: 모든 폴더를 active 상태로 (전체 열림 시작)
// HTML 구조에서 이미 active를 넣어두었거나 아래 코드로 실행 가능합니다.
$('.folder').addClass('active').next('ul').show();
// [2] 개별 폴더 클릭 토글
$(document).on('click', '.folder', function() {
$(this).next('ul').slideToggle(200);
$(this).toggleClass('active');
});
// [3] 전체 열기 버튼
$('#btn-expand').on('click', function() {
$('.folder').addClass('active').next('ul').slideDown(200);
});
// [4] 전체 닫기 버튼
$('#btn-collapse').on('click', function() {
$('.folder').removeClass('active').next('ul').slideUp(200);
});
// [5] 초성 검색 로직 (기존 유지)
$('#tree-search').on('input', function() {
const query = $(this).val().trim().toLowerCase();
const $allLi = $('#main-tree li');
const $noResult = $('#no-result');
$('.folder, .file').removeClass('highlight');
if (!query) {
$allLi.show();
$noResult.hide();
return;
}
$allLi.hide();
let hasVisibleItem = false;
$allLi.each(function() {
const text = $(this).children('.folder, .file').text();
if (Hangul.search(text.toLowerCase(), query) !== -1) {
$(this).show();
$(this).parents('li').show();
$(this).parents('ul').show();
$(this).parents('ul').prev('.folder').addClass('active');
$(this).children('.folder, .file').addClass('highlight');
hasVisibleItem = true;
}
});
hasVisibleItem ? $noResult.hide() : $noResult.show();
});
});
</script>
</body>
</html>
※ 해당 내용은 Google Gmini3.0에서 작성되었습니다.
'WEB > JQuery' 카테고리의 다른 글
| 전체 열기/닫기 & 동적 트리 통합 코드 (0) | 2026.01.22 |
|---|---|
| 상세 클릭포함 트리메뉴 (0) | 2026.01.22 |
| 폴더 트리메뉴 한글 검색포함 (1) | 2026.01.22 |
| 폴더 트리메뉴 (0) | 2026.01.22 |
| 모바일 전체 메뉴 (0) | 2026.01.18 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 정보처리기사 #정보처리기사요약 #정보처리기사요점정리
- 좋은책
- 파비콘 #파비콘 사이트에 적용
- 쇼팬하우어 #좋은책
- ajax
- 바지락칼국수 #월곡동칼국수 #칼국수맛집
- // 사진직: 데이터가 없으면 DEFAULT_IMG 사용 const profileSrc = (d.img && d.img !== "") ? d.img : DEFAULT_IMG;('#user-photo').attr('src'
- 증폭기 #아이피타임증폭기
- 파비콘사이즈
- thymeleaf
- SQL명령어 #SQL
- 자바스크립트break
- jdk #jre
- 무료폰트 #무료웹폰트 #한수원한돋움 #한수원한울림 #한울림체 #한돋움체
- 와이파이증폭기추천 #와이파이설치
- 자바스크립트정규표현식
- 탭메뉴자바스크립트
- 광주분식 #광주분식맛집 #상추튀김 #상추튀김맛집 #광주상추튀김
- 자바스크립트 #javascript #math
- 연명의료결정제도 #사전연명의료의향서 #사전연명의료의향서등록기관 #광주사전연명의료의향서
- jQuery #jQuery이미지슬라이드 #이미지슬라이드
- 자바스크립트countiue
- css미디어쿼리 #미디어쿼리 #mediaquery
- sw기술자평균임금 #2025년 sw기술자 평균임금
- 썬크림 #닥터지썬크림 #내돈내산 #내돈내산썬크림 #썬크림추천 #spf50썬크림 #닥터지메디유브이울트라선
- 테스크탑무선랜카드 #무선랜카드 #아이피타이무선랜카드 #a3000mini #무선랜카드추천
- iptime와이파이증폭기 #와이파이증폭기설치
- echart
- lg그램pro #lg그램 #노트북 #노트북추천 #lg노트북
- 좋은책 #밥프록터 #부의원리
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
글 보관함

