[jQuery] 입력한 내용에 맞는 체크박스만 보여주기

체크 박스 옵션이 많아져서 원하는 걸 찾기 어려울 때 사용하시면 됩니다.

몇 번 언급한 적이 있는 CoffeeScript를 사용했습니다.



[index.html]

<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
    <head>
        <title>Checkbox Filter</title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <link href="stylesheet.css" media="screen" rel="stylesheet" type="text/css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
        <script src="http://jashkenas.github.com/coffee-script/extras/coffee-script.js" type="text/javascript"></script>
        <script src="application.coffee" type="text/coffeescript"></script>
    </head>
    <body>
        <div id="container">
            <form method="post" action="/">
                <label for="input-filter">Filter:</label>
                <input id="input-filter" type="text" name="filter" />
                <ul>
                    <li>
                        <input id="id_1" type="checkbox" name="ids[]" value="1" />
                        <label for="id_1">#1 - AA</label>
                    </li>
                    <li>
                        <input id="id_2" type="checkbox" name="ids[]" value="2" />
                        <label for="id_2">#2 - BA</label>
                    </li>
                    <li>
                        <input id="id_3" type="checkbox" name="ids[]" value="3" />
                        <label for="id_3">#3 - AB</label>
                    </li>
                    <li>
                        <input id="id_4" type="checkbox" name="ids[]" value="4" />
                        <label for="id_4">#4 - BB</label>
                    </li>
                    <li>
                        <input id="id_5" type="checkbox" name="ids[]" value="5" />
                        <label for="id_5">#5 - ABC</label>
                    </li>
                </ul>
            </form>
        </div>
    </body>
</html>


[stylesheet.css]

body {
    font-size: 12px;
    background: #FFF;
    color: #333;
    margin: 0;
}

#container {
    margin: 10px auto;
    width: 600px;
    padding: 10px;
}


[application,coffee]

$ ->
  $('form').submit ->
    false

  $('input[name=filter]').live 'keyup', ->
    query = $(this).val().toLowerCase()
    if $(query).is(':blank')
      $('form li').show()
    else
      $('form li').each (i, item) ->
        text = $(item).find('label').text().toLowerCase()
        if text.search(query) < 0
          $(item).hide()
        else
          $(item).show()


|

댓글 2개

[application,coffee] 여기서 , 는 . 이게 맞는거죠?

유용하게 쓰이겠네요 감사합니다.
헉, 마침표가 맞습니다!
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
14년 전 조회 1,412
14년 전 조회 1,366
14년 전 조회 1,590
14년 전 조회 1,785
14년 전 조회 3,239
14년 전 조회 1,239
14년 전 조회 1,607
14년 전 조회 1,719
14년 전 조회 2,086
14년 전 조회 1,290
14년 전 조회 1,182
14년 전 조회 1,893
14년 전 조회 2,267
14년 전 조회 2,349
14년 전 조회 1,514
14년 전 조회 1,320
14년 전 조회 2,456
14년 전 조회 1,533
14년 전 조회 1,877
14년 전 조회 1,331
14년 전 조회 1,407
14년 전 조회 1,417
14년 전 조회 1,489
14년 전 조회 5,296
14년 전 조회 1,364
14년 전 조회 1,503
14년 전 조회 2,184
14년 전 조회 1,320
14년 전 조회 1,101
14년 전 조회 1,506
14년 전 조회 2,791
14년 전 조회 2,198
14년 전 조회 2,077
14년 전 조회 3,498
14년 전 조회 2,612
14년 전 조회 1,545
14년 전 조회 1,608
14년 전 조회 1,582
14년 전 조회 1,697
14년 전 조회 1,136
14년 전 조회 1,485
14년 전 조회 1,601
14년 전 조회 3,192
14년 전 조회 1,485
14년 전 조회 1,218
14년 전 조회 1,209
14년 전 조회 3,557
14년 전 조회 1,323
14년 전 조회 2,046
14년 전 조회 2,092
14년 전 조회 1,274
14년 전 조회 1,965
14년 전 조회 1,360
14년 전 조회 1,504
14년 전 조회 2,416
14년 전 조회 2,156
14년 전 조회 2,770
14년 전 조회 1,480
14년 전 조회 1,356
14년 전 조회 2,723
14년 전 조회 1,374
14년 전 조회 1,495
14년 전 조회 2,630
14년 전 조회 1,573
14년 전 조회 1,567
14년 전 조회 1,280
14년 전 조회 1,539
14년 전 조회 2,548
14년 전 조회 1,093
14년 전 조회 3,105
14년 전 조회 1,415
14년 전 조회 1,133
14년 전 조회 1,106
14년 전 조회 1,404
14년 전 조회 1,305
14년 전 조회 1,214
14년 전 조회 1,706
14년 전 조회 1,141
14년 전 조회 1,768
14년 전 조회 2,172
14년 전 조회 1,124
14년 전 조회 1,245
14년 전 조회 1,091
14년 전 조회 1,267
14년 전 조회 1,675
14년 전 조회 1,375
14년 전 조회 1,525
14년 전 조회 1,315
14년 전 조회 1,502
14년 전 조회 1,061
14년 전 조회 1,923
14년 전 조회 1,265
14년 전 조회 2,010
14년 전 조회 8,779
14년 전 조회 1,349
14년 전 조회 2,196
14년 전 조회 1,966
14년 전 조회 2,228
14년 전 조회 2,565
14년 전 조회 1,163