[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,746
14년 전 조회 1,673
14년 전 조회 1,898
14년 전 조회 2,086
14년 전 조회 3,560
14년 전 조회 1,582
14년 전 조회 1,912
14년 전 조회 2,046
14년 전 조회 2,419
14년 전 조회 1,634
14년 전 조회 1,491
14년 전 조회 2,214
14년 전 조회 2,567
14년 전 조회 2,641
14년 전 조회 1,818
14년 전 조회 1,618
14년 전 조회 2,741
14년 전 조회 1,828
14년 전 조회 2,227
14년 전 조회 1,649
14년 전 조회 1,737
14년 전 조회 1,698
14년 전 조회 1,784
14년 전 조회 5,630
14년 전 조회 1,672
14년 전 조회 1,807
14년 전 조회 2,478
14년 전 조회 1,629
14년 전 조회 1,418
14년 전 조회 1,777
14년 전 조회 3,081
14년 전 조회 2,492
14년 전 조회 2,337
14년 전 조회 3,776
14년 전 조회 2,885
14년 전 조회 1,851
14년 전 조회 1,896
14년 전 조회 1,863
14년 전 조회 1,976
14년 전 조회 1,443
14년 전 조회 1,758
14년 전 조회 1,886
14년 전 조회 3,444
14년 전 조회 1,753
14년 전 조회 1,510
14년 전 조회 1,493
14년 전 조회 3,849
14년 전 조회 1,621
14년 전 조회 2,333
14년 전 조회 2,362
14년 전 조회 1,554
14년 전 조회 2,234
14년 전 조회 1,631
14년 전 조회 1,769
14년 전 조회 2,689
14년 전 조회 2,435
14년 전 조회 3,058
14년 전 조회 1,751
14년 전 조회 1,633
14년 전 조회 3,014
14년 전 조회 1,647
14년 전 조회 1,765
14년 전 조회 2,896
14년 전 조회 1,889
14년 전 조회 1,841
14년 전 조회 1,540
14년 전 조회 1,790
14년 전 조회 2,820
14년 전 조회 1,396
14년 전 조회 3,367
14년 전 조회 1,719
14년 전 조회 1,415
14년 전 조회 1,409
14년 전 조회 1,666
14년 전 조회 1,582
14년 전 조회 1,482
14년 전 조회 2,001
14년 전 조회 1,397
14년 전 조회 2,047
14년 전 조회 2,437
14년 전 조회 1,392
14년 전 조회 1,548
14년 전 조회 1,369
14년 전 조회 1,536
14년 전 조회 1,979
14년 전 조회 1,666
14년 전 조회 1,787
14년 전 조회 1,586
14년 전 조회 1,765
14년 전 조회 1,338
14년 전 조회 2,211
14년 전 조회 1,540
14년 전 조회 2,295
14년 전 조회 9,051
14년 전 조회 1,628
14년 전 조회 2,471
14년 전 조회 2,203
14년 전 조회 2,461
14년 전 조회 2,834
14년 전 조회 1,423