[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년 전 조회 778
14년 전 조회 709
14년 전 조회 954
14년 전 조회 1,113
14년 전 조회 2,524
14년 전 조회 584
14년 전 조회 905
14년 전 조회 1,063
14년 전 조회 1,434
14년 전 조회 627
14년 전 조회 537
14년 전 조회 1,251
14년 전 조회 1,593
14년 전 조회 1,665
14년 전 조회 834
14년 전 조회 648
14년 전 조회 1,801
14년 전 조회 872
14년 전 조회 1,246
14년 전 조회 698
14년 전 조회 753
14년 전 조회 741
14년 전 조회 836
14년 전 조회 4,639
14년 전 조회 748
14년 전 조회 867
14년 전 조회 1,524
14년 전 조회 689
14년 전 조회 483
14년 전 조회 860
14년 전 조회 2,131
14년 전 조회 1,598
14년 전 조회 1,421
14년 전 조회 2,850
14년 전 조회 1,965
14년 전 조회 915
14년 전 조회 988
14년 전 조회 939
14년 전 조회 1,040
14년 전 조회 531
14년 전 조회 838
14년 전 조회 989
14년 전 조회 2,535
14년 전 조회 849
14년 전 조회 583
14년 전 조회 601
14년 전 조회 2,952
14년 전 조회 735
14년 전 조회 1,448
14년 전 조회 1,453
14년 전 조회 648
14년 전 조회 1,369
14년 전 조회 760
14년 전 조회 867
14년 전 조회 1,835
14년 전 조회 1,535
14년 전 조회 2,139
14년 전 조회 869
14년 전 조회 754
14년 전 조회 2,140
14년 전 조회 770
14년 전 조회 880
14년 전 조회 1,992
14년 전 조회 1,007
14년 전 조회 918
14년 전 조회 663
14년 전 조회 910
14년 전 조회 1,923
14년 전 조회 492
14년 전 조회 2,449
14년 전 조회 818
14년 전 조회 527
14년 전 조회 526
14년 전 조회 793
14년 전 조회 697
14년 전 조회 595
14년 전 조회 1,086
14년 전 조회 519
14년 전 조회 1,200
14년 전 조회 1,570
14년 전 조회 534
14년 전 조회 663
14년 전 조회 516
14년 전 조회 665
14년 전 조회 1,096
14년 전 조회 791
14년 전 조회 913
14년 전 조회 736
14년 전 조회 881
14년 전 조회 470
14년 전 조회 1,282
14년 전 조회 628
14년 전 조회 1,384
14년 전 조회 8,138
14년 전 조회 761
14년 전 조회 1,607
14년 전 조회 1,329
14년 전 조회 1,603
14년 전 조회 1,939
14년 전 조회 539
🐛 버그신고