간단한 셀렉트 드롭다운 제이쿼리

· 10년 전 · 445

 html

 

<div class="select">

    <a href="#">Select 1</a>

    <ul>

        <li>Select 1</li>

        <li>Select 2</li>

        <li>Select 3</li>

    </ul>

</div>

 

 

css

 

.select {position:relative; line-height:35px;}

.select > a {display:block; border:1px solid #ccc; padding:0 8px; overflow:hidden;}

.select > a:after,

.select > ul > li:first-child:after {display:block; float:right;}

.select > a:after {content:'▼';}

.select > ul {position:absolute; width:100%; top:1px; background:#fff; display:none;}

.select > ul > li {cursor:pointer; padding:0 8px; border:1px solid #ccc; border-top:0;}

.select > ul > li:first-child:after {content:'▲';}

 

 

 

Jquery

 

$("div.select > a").click(function() {

    $(this).next("ul").toggle();

    return false;

});

 

$("div.select > ul > li").click(function() {

    $(this).parent().hide().parent("div.select").children("a").text($(this).text());

    $(this).prependTo($(this).parent());

});

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

팁게시판

디자인과 관련된 유용한 정보를 공유하세요. 질문은 상단의 QA에서 해주시기 바랍니다.

+
제목 글쓴이 날짜 조회
10년 전 조회 405
10년 전 조회 279
10년 전 조회 243
10년 전 조회 265
10년 전 조회 373
10년 전 조회 283
10년 전 조회 235
10년 전 조회 238
10년 전 조회 246
10년 전 조회 199
10년 전 조회 203
10년 전 조회 380
10년 전 조회 446
10년 전 조회 233
10년 전 조회 229
10년 전 조회 194
10년 전 조회 207
10년 전 조회 306
10년 전 조회 232
10년 전 조회 161
10년 전 조회 213
10년 전 조회 587
10년 전 조회 518
10년 전 조회 373
10년 전 조회 281
🐛 버그신고