[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년 전 조회 791
14년 전 조회 724
14년 전 조회 969
14년 전 조회 1,126
14년 전 조회 2,537
14년 전 조회 597
14년 전 조회 915
14년 전 조회 1,073
14년 전 조회 1,446
14년 전 조회 641
14년 전 조회 547
14년 전 조회 1,260
14년 전 조회 1,605
14년 전 조회 1,676
14년 전 조회 847
14년 전 조회 659
14년 전 조회 1,817
14년 전 조회 882
14년 전 조회 1,260
14년 전 조회 707
14년 전 조회 769
14년 전 조회 756
14년 전 조회 848
14년 전 조회 4,649
14년 전 조회 765
14년 전 조회 878
14년 전 조회 1,536
14년 전 조회 703
14년 전 조회 494
14년 전 조회 875
14년 전 조회 2,147
14년 전 조회 1,611
14년 전 조회 1,432
14년 전 조회 2,858
14년 전 조회 1,975
14년 전 조회 931
14년 전 조회 1,003
14년 전 조회 949
14년 전 조회 1,054
14년 전 조회 540
14년 전 조회 851
14년 전 조회 998
14년 전 조회 2,546
14년 전 조회 864
14년 전 조회 596
14년 전 조회 614
14년 전 조회 2,961
14년 전 조회 747
14년 전 조회 1,463
14년 전 조회 1,465
14년 전 조회 658
14년 전 조회 1,377
14년 전 조회 771
14년 전 조회 881
14년 전 조회 1,843
14년 전 조회 1,549
14년 전 조회 2,155
14년 전 조회 885
14년 전 조회 769
14년 전 조회 2,156
14년 전 조회 783
14년 전 조회 890
14년 전 조회 2,007
14년 전 조회 1,017
14년 전 조회 927
14년 전 조회 673
14년 전 조회 923
14년 전 조회 1,937
14년 전 조회 503
14년 전 조회 2,460
14년 전 조회 834
14년 전 조회 539
14년 전 조회 538
14년 전 조회 806
14년 전 조회 714
14년 전 조회 609
14년 전 조회 1,096
14년 전 조회 534
14년 전 조회 1,213
14년 전 조회 1,578
14년 전 조회 545
14년 전 조회 673
14년 전 조회 525
14년 전 조회 675
14년 전 조회 1,105
14년 전 조회 802
14년 전 조회 922
14년 전 조회 746
14년 전 조회 895
14년 전 조회 482
14년 전 조회 1,293
14년 전 조회 644
14년 전 조회 1,396
14년 전 조회 8,144
14년 전 조회 779
14년 전 조회 1,616
14년 전 조회 1,339
14년 전 조회 1,617
14년 전 조회 1,952
14년 전 조회 552
🐛 버그신고