천

textarea 글자수 카운트 입니다.

· 2016-01-05 (화) 11:12:21 · 2753 · 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-05-11 조회 3,059
16-03-11 조회 2,874
16-03-09 조회 2,952
16-02-18 조회 3,098
16-01-28 조회 2,603
16-01-26 조회 2,526
16-01-22 조회 2,540
16-01-21 조회 2,542
16-01-14 조회 2,704
16-01-13 조회 2,562
16-01-12 조회 2,538
16-01-03 조회 3,309
16-01-03 조회 2,633
16-01-03 조회 2,886
16-01-02 조회 2,568
16-01-02 조회 2,689
16-01-02 조회 2,464
16-01-01 조회 2,755
16-01-01 조회 2,684
16-01-01 조회 2,747
15-12-31 조회 2,829
15-12-31 조회 2,860
15-12-31 조회 2,678
15-12-30 조회 2,713
15-12-30 조회 2,618
15-12-30 조회 2,549
15-12-29 조회 2,761
15-12-29 조회 2,860
15-12-29 조회 2,588
15-12-28 조회 2,627
15-12-28 조회 2,653
15-12-28 조회 2,492
15-11-26 조회 2,785
15-11-03 조회 3,389
15-11-02 조회 2,628
15-10-30 조회 3,228
15-10-30 조회 2,643
15-10-29 조회 2,723
15-10-03 조회 3,552
15-10-03 조회 2,787
15-10-02 조회 2,741
15-09-30 조회 2,615
15-09-30 조회 2,762
15-09-30 조회 2,843
15-09-30 조회 2,848
15-09-24 조회 2,796
15-09-24 조회 2,726
15-09-23 조회 3,116
15-09-23 조회 2,632
15-09-23 조회 2,712
15-09-23 조회 2,914
15-09-21 조회 2,640
15-09-21 조회 2,657
15-09-21 조회 2,725
15-07-02 조회 3,108
15-02-09 조회 4,705
15-01-24 조회 5,365
14-12-18 조회 5,400
14-11-21 조회 4,080
14-08-23 조회 3,850
14-08-11 조회 4,505
14-08-06 조회 6,249
14-08-01 조회 4,081
14-06-24 조회 5,871
14-05-18 조회 4,872
14-05-15 조회 4,559
14-05-15 조회 5,490
14-05-13 조회 4,793
14-05-09 조회 4,072
14-04-22 조회 4,558
14-04-16 조회 5,512
14-03-17 조회 7,269
13-11-12 조회 5,584
13-10-18 조회 4,454
13-10-15 조회 4,698
13-08-22 조회 4,630
13-08-18 조회 8,489
13-07-23 조회 7,287
13-07-23 조회 8,412
13-07-07 조회 5,415
13-05-18 조회 6,547
13-04-02 조회 6,049
13-04-02 조회 6,962
13-04-02 조회 7,300
13-04-02 조회 4,425
13-03-25 조회 4,001
13-03-20 조회 1.2만
13-02-12 조회 3,896
13-01-25 조회 4,817
13-01-17 조회 3,974
13-01-11 조회 4,215
13-01-01 조회 7,106
12-12-30 조회 5,998
12-12-17 조회 3,616
12-12-02 조회 7,341
12-11-29 조회 3,978
12-11-27 조회 4,883
12-10-05 조회 5,640
12-10-03 조회 4,566
12-09-14 조회 4,339