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

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

· 9년 전 · 446

 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());

});

댓글 작성

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

로그인하기

게시글 목록

번호 제목
12357
12356
12355
12354
12353
20387
12352
12351
12350
12349
12348
12347
12346
12345
12344
12343
12342
12341
12340
12339
12338
12337
12336
12335
12334