textarea 글자수 카운트 입니다.

· 2016-01-05 (화) 11:12:21 · 2688 · 1

index.html

<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
    <head>
        <title>Input Counter</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="application.js" type="text/javascript"></script>
    </head>
    <body>
        <div id="container">
            <form action="index.html" method="POST">
                <textarea></textarea>
                <span class="input-counter"></span>
                <input type="submit" id="input-submit" value="등록" />
            </form>
        </div>
    </body>
</html>


stylesheet.js

body {
    font-size: 12px;
    background: #FFF;
    color: #333;
    margin: 0;
}

#container {
    margin: 10px auto;
    width: 500px;
    padding: 10px;
    background: #CCC;
}

form {
    overflow: hidden;
    height: 100%;
}

textarea {
    display: block;
    width: 99%;
    height: 5.0em;
    margin-bottom: 0.5em;
}

span.input-counter {
    float: left;
    font-weight: bold;
    color: #000;
}

span.input-counter.disabled {
    color: #F00;
}

input#input-submit {
    float: right;
}


application.js

$(function() {
    var maxLength = 140;

    function updateInputCount() {
        var textLength = $('textarea').val().length;
        var count = maxLength - textLength;
        $('span.input-counter').text(count);
        if (count < 0) {
            $('span.input-counter').addClass('disabled');
            $('input#input-submit').prop('disabled', true);
        } else {
            $('span.input-counter').removeClass('disabled');
            $('input#input-submit').prop('disabled', false);
        }
    }

    $('textarea')
        .focus(updateInputCount)
        .blur(updateInputCount)
        .keypress(updateInputCount);
    window.setInterval(updateInputCount, 100);

    updateInputCount();
});

|

댓글 1개

감사합니다.
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

8,188건
+
제목 글쓴이 날짜 조회
16-06-11 조회 2,836
16-02-15 조회 3,140
16-02-02 조회 2,811
16-01-25 조회 2,428
16-01-18 조회 2,526
16-01-08 조회 2,453
16-01-07 조회 2,496
16-01-05 조회 2,500
16-01-05 조회 2,788
16-01-05 조회 2,627
16-01-05 조회 2,689
16-01-04 조회 2,470
16-01-04 조회 2,569
16-01-04 조회 2,525
16-01-04 조회 2,443
15-12-30 조회 2,719
15-12-24 조회 2,549
15-12-24 조회 2,591
15-12-24 조회 2,613
15-12-24 조회 2,569
15-12-23 조회 2,536
15-12-16 조회 2,644
15-12-15 조회 2,727
15-12-11 조회 2,781
15-12-10 조회 2,709
15-11-09 조회 2,690
15-11-09 조회 2,831
15-10-06 조회 3,183
15-10-02 조회 3,034
15-05-29 조회 4,378
15-02-02 조회 4,159
15-01-18 조회 4,094
14-10-25 조회 8,170
14-10-25 조회 4,995
14-10-22 조회 6,981
14-10-22 조회 4,741
14-10-22 조회 4,675
14-10-18 조회 5,424
14-10-17 조회 5,792
14-10-17 조회 5,224
14-10-17 조회 8,665
14-10-17 조회 6,223
14-10-13 조회 4,055
14-10-13 조회 4,291
14-10-07 조회 6,027
14-09-24 조회 3,817
14-09-23 조회 3,891
14-09-22 조회 4,660
14-09-22 조회 5,907
14-09-22 조회 3,911
14-09-22 조회 3,548
14-09-21 조회 4,081
14-09-21 조회 3,656
14-09-20 조회 3,648
14-09-20 조회 3,576
14-09-20 조회 3,748
14-09-19 조회 3,627
14-09-19 조회 3,790
14-09-19 조회 3,663
14-09-19 조회 3,973
14-09-19 조회 3,740
14-09-19 조회 3,676
14-09-19 조회 3,868
14-09-19 조회 3,624
14-09-19 조회 3,621
14-09-19 조회 3,668
14-09-18 조회 3,668
14-09-18 조회 3,699
14-09-18 조회 3,858
14-09-18 조회 3,868
14-09-18 조회 3,894
14-09-18 조회 4,661
14-09-18 조회 5,263
14-09-18 조회 5,180
14-09-18 조회 3,974
14-09-18 조회 4,480
14-09-18 조회 4,118
14-08-30 조회 5,228
14-08-06 조회 5,864
14-08-06 조회 5,458
14-08-03 조회 4,945
14-06-12 조회 5,230
14-05-11 조회 3,575
14-05-11 조회 4,369
14-05-11 조회 4,464
14-05-09 조회 1.2만
14-05-01 조회 4,801
14-03-30 조회 4,308
14-03-23 조회 7,813
14-02-12 조회 3,768
13-10-29 조회 7,610
13-10-28 조회 8,542
13-09-29 조회 6,535
13-09-29 조회 4,168
13-07-23 조회 4,849
13-07-23 조회 1.2만
13-07-14 조회 4,617
13-07-14 조회 4,918
13-07-14 조회 5,930
13-07-14 조회 5,070