[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년 전 조회 807
14년 전 조회 734
14년 전 조회 985
14년 전 조회 1,141
14년 전 조회 2,546
14년 전 조회 604
14년 전 조회 935
14년 전 조회 1,082
14년 전 조회 1,457
14년 전 조회 654
14년 전 조회 563
14년 전 조회 1,273
14년 전 조회 1,624
14년 전 조회 1,694
14년 전 조회 864
14년 전 조회 672
14년 전 조회 1,824
14년 전 조회 897
14년 전 조회 1,274
14년 전 조회 720
14년 전 조회 784
14년 전 조회 768
14년 전 조회 862
14년 전 조회 4,663
14년 전 조회 778
14년 전 조회 895
14년 전 조회 1,553
14년 전 조회 713
14년 전 조회 507
14년 전 조회 887
14년 전 조회 2,164
14년 전 조회 1,622
14년 전 조회 1,444
14년 전 조회 2,872
14년 전 조회 1,981
14년 전 조회 946
14년 전 조회 1,016
14년 전 조회 958
14년 전 조회 1,067
14년 전 조회 550
14년 전 조회 862
14년 전 조회 1,012
14년 전 조회 2,553
14년 전 조회 881
14년 전 조회 613
14년 전 조회 628
14년 전 조회 2,973
14년 전 조회 759
14년 전 조회 1,472
14년 전 조회 1,479
14년 전 조회 669
14년 전 조회 1,392
14년 전 조회 782
14년 전 조회 895
14년 전 조회 1,856
14년 전 조회 1,562
14년 전 조회 2,169
14년 전 조회 895
14년 전 조회 780
14년 전 조회 2,168
14년 전 조회 793
14년 전 조회 899
14년 전 조회 2,020
14년 전 조회 1,033
14년 전 조회 942
14년 전 조회 691
14년 전 조회 931
14년 전 조회 1,947
14년 전 조회 515
14년 전 조회 2,473
14년 전 조회 848
14년 전 조회 549
14년 전 조회 554
14년 전 조회 820
14년 전 조회 725
14년 전 조회 621
14년 전 조회 1,109
14년 전 조회 546
14년 전 조회 1,221
14년 전 조회 1,589
14년 전 조회 557
14년 전 조회 689
14년 전 조회 534
14년 전 조회 684
14년 전 조회 1,123
14년 전 조회 815
14년 전 조회 928
14년 전 조회 754
14년 전 조회 906
14년 전 조회 489
14년 전 조회 1,302
14년 전 조회 653
14년 전 조회 1,406
14년 전 조회 8,153
14년 전 조회 789
14년 전 조회 1,626
14년 전 조회 1,346
14년 전 조회 1,627
14년 전 조회 1,965
14년 전 조회 564
🐛 버그신고