[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,772
14년 전 조회 1,700
14년 전 조회 1,921
14년 전 조회 2,106
14년 전 조회 3,584
14년 전 조회 1,601
14년 전 조회 1,937
14년 전 조회 2,070
14년 전 조회 2,435
14년 전 조회 1,661
14년 전 조회 1,504
14년 전 조회 2,235
14년 전 조회 2,582
14년 전 조회 2,660
14년 전 조회 1,839
14년 전 조회 1,637
14년 전 조회 2,756
14년 전 조회 1,850
14년 전 조회 2,242
14년 전 조회 1,669
14년 전 조회 1,754
14년 전 조회 1,718
14년 전 조회 1,808
14년 전 조회 5,648
14년 전 조회 1,688
14년 전 조회 1,827
14년 전 조회 2,501
14년 전 조회 1,640
14년 전 조회 1,435
14년 전 조회 1,795
14년 전 조회 3,101
14년 전 조회 2,510
14년 전 조회 2,358
14년 전 조회 3,793
14년 전 조회 2,899
14년 전 조회 1,868
14년 전 조회 1,916
14년 전 조회 1,879
14년 전 조회 1,992
14년 전 조회 1,463
14년 전 조회 1,783
14년 전 조회 1,906
14년 전 조회 3,464
14년 전 조회 1,769
14년 전 조회 1,527
14년 전 조회 1,511
14년 전 조회 3,870
14년 전 조회 1,642
14년 전 조회 2,349
14년 전 조회 2,384
14년 전 조회 1,575
14년 전 조회 2,253
14년 전 조회 1,648
14년 전 조회 1,783
14년 전 조회 2,713
14년 전 조회 2,453
14년 전 조회 3,077
14년 전 조회 1,782
14년 전 조회 1,658
14년 전 조회 3,034
14년 전 조회 1,669
14년 전 조회 1,781
14년 전 조회 2,914
14년 전 조회 1,909
14년 전 조회 1,860
14년 전 조회 1,558
14년 전 조회 1,810
14년 전 조회 2,832
14년 전 조회 1,417
14년 전 조회 3,386
14년 전 조회 1,737
14년 전 조회 1,431
14년 전 조회 1,423
14년 전 조회 1,688
14년 전 조회 1,602
14년 전 조회 1,499
14년 전 조회 2,012
14년 전 조회 1,414
14년 전 조회 2,062
14년 전 조회 2,445
14년 전 조회 1,411
14년 전 조회 1,570
14년 전 조회 1,392
14년 전 조회 1,551
14년 전 조회 1,997
14년 전 조회 1,681
14년 전 조회 1,803
14년 전 조회 1,605
14년 전 조회 1,775
14년 전 조회 1,356
14년 전 조회 2,226
14년 전 조회 1,563
14년 전 조회 2,316
14년 전 조회 9,063
14년 전 조회 1,650
14년 전 조회 2,489
14년 전 조회 2,222
14년 전 조회 2,477
14년 전 조회 2,855
14년 전 조회 1,443