천

textarea 글자수 카운트 입니다.

· 2016-01-05 (화) 11:12:21 · 2744 · 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-30 조회 2,775
16-05-11 조회 3,336
16-03-21 조회 3,114
16-03-19 조회 3,068
16-03-17 조회 2,890
16-03-17 조회 2,976
16-03-14 조회 2,990
16-03-13 조회 2,918
16-03-09 조회 3,352
16-03-08 조회 3,000
16-03-08 조회 2,809
16-03-08 조회 2,825
16-03-08 조회 2,979
16-03-07 조회 2,775
16-03-07 조회 2,774
16-02-29 조회 3,171
16-02-25 조회 3,161
16-02-22 조회 2,970
16-02-12 조회 3,254
16-02-04 조회 3,091
16-02-04 조회 3,357
16-02-04 조회 2,988
16-02-03 조회 3,159
16-02-03 조회 2,976
16-02-02 조회 2,927
16-02-02 조회 2,809
16-02-01 조회 2,821
16-01-30 조회 2,650
16-01-30 조회 2,833
16-01-30 조회 2,933
16-01-30 조회 2,754
16-01-29 조회 2,638
16-01-28 조회 2,935
16-01-28 조회 2,577
16-01-27 조회 2,539
16-01-26 조회 2,502
16-01-26 조회 2,595
16-01-25 조회 2,570
16-01-22 조회 2,548
16-01-22 조회 2,622
16-01-21 조회 2,527
16-01-19 조회 2,437
16-01-19 조회 2,490
16-01-18 조회 2,459
16-01-17 조회 2,631
16-01-14 조회 2,569
16-01-13 조회 2,749
16-01-12 조회 2,857
16-01-12 조회 2,611
16-01-11 조회 2,566
15-12-30 조회 3,183
15-12-29 조회 2,566
15-12-28 조회 2,592
15-12-09 조회 2,667
15-12-08 조회 2,873
15-12-08 조회 2,621
15-12-08 조회 2,899
15-12-07 조회 2,703
15-12-07 조회 3,071
15-12-07 조회 2,730
15-12-06 조회 2,861
15-12-06 조회 2,565
15-12-06 조회 2,786
15-12-05 조회 2,717
15-12-05 조회 2,973
15-12-05 조회 2,766
15-12-04 조회 2,625
15-12-04 조회 2,739
15-12-04 조회 2,786
15-12-03 조회 2,745
15-12-03 조회 2,778
15-12-03 조회 2,791
15-12-02 조회 2,884
15-12-02 조회 2,822
15-12-02 조회 2,951
15-12-02 조회 2,999
15-12-01 조회 2,714
15-12-01 조회 2,510
15-12-01 조회 2,583
15-11-30 조회 2,780
15-11-30 조회 2,918
15-11-30 조회 2,834
15-11-29 조회 2,605
15-11-29 조회 2,842
15-11-29 조회 2,665
15-11-28 조회 2,604
15-11-28 조회 2,620
15-11-28 조회 2,665
15-11-27 조회 2,758
15-11-27 조회 2,606
15-11-27 조회 2,617
15-11-25 조회 2,685
15-11-25 조회 2,748
15-11-25 조회 2,544
15-11-23 조회 2,822
15-11-23 조회 2,954
15-11-23 조회 2,795
15-11-21 조회 2,689
15-11-21 조회 2,588
15-11-21 조회 2,534