[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년 전 조회 764
14년 전 조회 697
14년 전 조회 943
14년 전 조회 1,100
14년 전 조회 2,512
14년 전 조회 570
14년 전 조회 891
14년 전 조회 1,053
14년 전 조회 1,423
14년 전 조회 614
14년 전 조회 526
14년 전 조회 1,242
14년 전 조회 1,580
14년 전 조회 1,655
14년 전 조회 825
14년 전 조회 639
14년 전 조회 1,790
14년 전 조회 860
14년 전 조회 1,233
14년 전 조회 685
14년 전 조회 743
14년 전 조회 731
14년 전 조회 823
14년 전 조회 4,628
14년 전 조회 735
14년 전 조회 855
14년 전 조회 1,510
14년 전 조회 675
14년 전 조회 471
14년 전 조회 847
14년 전 조회 2,116
14년 전 조회 1,585
14년 전 조회 1,408
14년 전 조회 2,838
14년 전 조회 1,951
14년 전 조회 902
14년 전 조회 974
14년 전 조회 927
14년 전 조회 1,027
14년 전 조회 519
14년 전 조회 826
14년 전 조회 974
14년 전 조회 2,526
14년 전 조회 840
14년 전 조회 571
14년 전 조회 589
14년 전 조회 2,938
14년 전 조회 721
14년 전 조회 1,433
14년 전 조회 1,438
14년 전 조회 635
14년 전 조회 1,356
14년 전 조회 746
14년 전 조회 856
14년 전 조회 1,821
14년 전 조회 1,521
14년 전 조회 2,126
14년 전 조회 857
14년 전 조회 739
14년 전 조회 2,130
14년 전 조회 757
14년 전 조회 866
14년 전 조회 1,979
14년 전 조회 997
14년 전 조회 904
14년 전 조회 649
14년 전 조회 893
14년 전 조회 1,911
14년 전 조회 477
14년 전 조회 2,439
14년 전 조회 806
14년 전 조회 512
14년 전 조회 517
14년 전 조회 780
14년 전 조회 686
14년 전 조회 584
14년 전 조회 1,071
14년 전 조회 509
14년 전 조회 1,190
14년 전 조회 1,557
14년 전 조회 523
14년 전 조회 650
14년 전 조회 504
14년 전 조회 655
14년 전 조회 1,083
14년 전 조회 779
14년 전 조회 901
14년 전 조회 725
14년 전 조회 867
14년 전 조회 460
14년 전 조회 1,269
14년 전 조회 614
14년 전 조회 1,373
14년 전 조회 8,126
14년 전 조회 752
14년 전 조회 1,592
14년 전 조회 1,315
14년 전 조회 1,591
14년 전 조회 1,929
14년 전 조회 526
🐛 버그신고