천

textarea 글자수 카운트 입니다.

· 2016-01-05 (화) 11:12:21 · 2709 · 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-01-11 조회 2,293
16-01-11 조회 2,361
16-01-11 조회 2,350
16-01-08 조회 2,768
16-01-08 조회 2,513
16-01-07 조회 2,531
16-01-05 조회 2,519
16-01-05 조회 2,545
16-01-05 조회 2,848
16-01-05 조회 2,680
16-01-05 조회 2,710
16-01-04 조회 2,495
16-01-04 조회 2,594
16-01-04 조회 2,545
16-01-04 조회 2,459
16-01-03 조회 3,257
16-01-03 조회 2,601
16-01-03 조회 2,801
16-01-02 조회 2,789
16-01-02 조회 2,535
16-01-02 조회 2,648
16-01-02 조회 2,438
16-01-01 조회 2,730
16-01-01 조회 2,647
16-01-01 조회 2,656
15-12-31 조회 2,498
15-12-31 조회 3,196
15-12-31 조회 2,758
15-12-31 조회 2,799
15-12-31 조회 2,641
15-12-30 조회 2,598
15-12-30 조회 3,100
15-12-30 조회 2,782
15-12-30 조회 2,670
15-12-30 조회 2,541
15-12-30 조회 2,513
15-12-29 조회 2,540
15-12-29 조회 2,704
15-12-29 조회 2,810
15-12-29 조회 2,557
15-12-28 조회 2,578
15-12-28 조회 2,592
15-12-28 조회 2,571
15-12-28 조회 2,470
15-12-27 조회 3,143
15-12-27 조회 2,604
15-12-27 조회 2,514
15-12-27 조회 2,566
15-12-26 조회 2,533
15-12-26 조회 2,599
15-12-26 조회 2,602
15-12-25 조회 3,276
15-12-25 조회 2,499
15-12-25 조회 2,496
15-12-25 조회 2,439
15-12-24 조회 2,990
15-12-24 조회 2,604
15-12-24 조회 2,612
15-12-24 조회 2,641
15-12-24 조회 2,599
15-12-23 조회 2,743
15-12-23 조회 2,576
15-12-23 조회 2,445
15-12-23 조회 2,576
15-12-23 조회 2,521
15-12-22 조회 2,710
15-12-22 조회 2,565
15-12-22 조회 2,561
15-12-22 조회 2,467
15-12-21 조회 2,494
15-12-21 조회 2,536
15-12-21 조회 2,504
15-12-20 조회 2,546
15-12-20 조회 2,699
15-12-20 조회 2,495
15-12-19 조회 2,565
15-12-19 조회 2,552
15-12-19 조회 2,568
15-12-18 조회 2,856
15-12-18 조회 2,550
15-12-18 조회 2,527
15-12-18 조회 2,518
15-12-17 조회 2,567
15-12-17 조회 2,502
15-12-17 조회 2,500
15-12-17 조회 2,466
15-12-16 조회 2,483
15-12-16 조회 2,529
15-12-16 조회 2,462
15-12-16 조회 2,663
15-12-15 조회 2,813
15-12-15 조회 2,747
15-12-15 조회 2,476
15-12-15 조회 2,467
15-12-15 조회 2,465
15-12-14 조회 2,544
15-12-14 조회 2,621
15-12-14 조회 2,452
15-12-13 조회 2,428
15-12-13 조회 2,459