[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,356
14년 전 조회 1,310
14년 전 조회 1,539
14년 전 조회 1,717
14년 전 조회 3,188
14년 전 조회 1,182
14년 전 조회 1,517
14년 전 조회 1,661
14년 전 조회 2,028
14년 전 조회 1,229
14년 전 조회 1,123
14년 전 조회 1,842
14년 전 조회 2,208
14년 전 조회 2,290
14년 전 조회 1,473
14년 전 조회 1,265
14년 전 조회 2,406
14년 전 조회 1,485
14년 전 조회 1,821
14년 전 조회 1,271
14년 전 조회 1,336
14년 전 조회 1,371
14년 전 조회 1,429
14년 전 조회 5,252
14년 전 조회 1,307
14년 전 조회 1,459
14년 전 조회 2,133
14년 전 조회 1,267
14년 전 조회 1,049
14년 전 조회 1,455
14년 전 조회 2,722
14년 전 조회 2,160
14년 전 조회 2,016
14년 전 조회 3,464
14년 전 조회 2,550
14년 전 조회 1,495
14년 전 조회 1,545
14년 전 조회 1,527
14년 전 조회 1,647
14년 전 조회 1,085
14년 전 조회 1,411
14년 전 조회 1,538
14년 전 조회 3,138
14년 전 조회 1,440
14년 전 조회 1,171
14년 전 조회 1,158
14년 전 조회 3,502
14년 전 조회 1,277
14년 전 조회 1,989
14년 전 조회 2,063
14년 전 조회 1,213
14년 전 조회 1,910
14년 전 조회 1,299
14년 전 조회 1,449
14년 전 조회 2,367
14년 전 조회 2,121
14년 전 조회 2,721
14년 전 조회 1,439
14년 전 조회 1,306
14년 전 조회 2,669
14년 전 조회 1,327
14년 전 조회 1,434
14년 전 조회 2,587
14년 전 조회 1,522
14년 전 조회 1,516
14년 전 조회 1,229
14년 전 조회 1,490
14년 전 조회 2,495
14년 전 조회 1,047
14년 전 조회 3,052
14년 전 조회 1,364
14년 전 조회 1,088
14년 전 조회 1,053
14년 전 조회 1,341
14년 전 조회 1,261
14년 전 조회 1,161
14년 전 조회 1,657
14년 전 조회 1,083
14년 전 조회 1,725
14년 전 조회 2,131
14년 전 조회 1,081
14년 전 조회 1,190
14년 전 조회 1,039
14년 전 조회 1,214
14년 전 조회 1,623
14년 전 조회 1,328
14년 전 조회 1,467
14년 전 조회 1,265
14년 전 조회 1,451
14년 전 조회 1,018
14년 전 조회 1,849
14년 전 조회 1,197
14년 전 조회 1,973
14년 전 조회 8,739
14년 전 조회 1,308
14년 전 조회 2,136
14년 전 조회 1,920
14년 전 조회 2,180
14년 전 조회 2,532
14년 전 조회 1,101