[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,595
14년 전 조회 1,521
14년 전 조회 1,745
14년 전 조회 1,942
14년 전 조회 3,398
14년 전 조회 1,414
14년 전 조회 1,756
14년 전 조회 1,877
14년 전 조회 2,258
14년 전 조회 1,466
14년 전 조회 1,364
14년 전 조회 2,048
14년 전 조회 2,406
14년 전 조회 2,487
14년 전 조회 1,667
14년 전 조회 1,476
14년 전 조회 2,588
14년 전 조회 1,687
14년 전 조회 2,060
14년 전 조회 1,496
14년 전 조회 1,593
14년 전 조회 1,545
14년 전 조회 1,628
14년 전 조회 5,495
14년 전 조회 1,544
14년 전 조회 1,671
14년 전 조회 2,338
14년 전 조회 1,488
14년 전 조회 1,286
14년 전 조회 1,630
14년 전 조회 2,931
14년 전 조회 2,356
14년 전 조회 2,207
14년 전 조회 3,650
14년 전 조회 2,739
14년 전 조회 1,700
14년 전 조회 1,752
14년 전 조회 1,726
14년 전 조회 1,845
14년 전 조회 1,312
14년 전 조회 1,624
14년 전 조회 1,752
14년 전 조회 3,333
14년 전 조회 1,638
14년 전 조회 1,381
14년 전 조회 1,379
14년 전 조회 3,719
14년 전 조회 1,494
14년 전 조회 2,187
14년 전 조회 2,233
14년 전 조회 1,426
14년 전 조회 2,101
14년 전 조회 1,511
14년 전 조회 1,636
14년 전 조회 2,560
14년 전 조회 2,297
14년 전 조회 2,906
14년 전 조회 1,615
14년 전 조회 1,502
14년 전 조회 2,876
14년 전 조회 1,524
14년 전 조회 1,650
14년 전 조회 2,765
14년 전 조회 1,748
14년 전 조회 1,690
14년 전 조회 1,412
14년 전 조회 1,651
14년 전 조회 2,682
14년 전 조회 1,267
14년 전 조회 3,225
14년 전 조회 1,576
14년 전 조회 1,299
14년 전 조회 1,276
14년 전 조회 1,529
14년 전 조회 1,456
14년 전 조회 1,363
14년 전 조회 1,855
14년 전 조회 1,291
14년 전 조회 1,911
14년 전 조회 2,299
14년 전 조회 1,269
14년 전 조회 1,411
14년 전 조회 1,256
14년 전 조회 1,424
14년 전 조회 1,837
14년 전 조회 1,538
14년 전 조회 1,653
14년 전 조회 1,467
14년 전 조회 1,627
14년 전 조회 1,218
14년 전 조회 2,078
14년 전 조회 1,410
14년 전 조회 2,161
14년 전 조회 8,911
14년 전 조회 1,512
14년 전 조회 2,347
14년 전 조회 2,079
14년 전 조회 2,335
14년 전 조회 2,722
14년 전 조회 1,303