textarea 글자수 카운트 입니다.

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개

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

프로그램

+
제목 글쓴이 날짜 조회
10년 전 조회 1,415
10년 전 조회 1,354
10년 전 조회 1,332
10년 전 조회 1,322
10년 전 조회 1,351
10년 전 조회 1,446
10년 전 조회 1,367
10년 전 조회 1,458
10년 전 조회 1,374
10년 전 조회 1,415
10년 전 조회 1,405
10년 전 조회 1,464
10년 전 조회 1,531
10년 전 조회 1,595
10년 전 조회 1,409
10년 전 조회 1,454
10년 전 조회 1,357
10년 전 조회 1,277
10년 전 조회 1,330
10년 전 조회 1,448
10년 전 조회 1,374
10년 전 조회 1,385
10년 전 조회 1,365
10년 전 조회 1,518
10년 전 조회 1,490
10년 전 조회 1,991
10년 전 조회 1,381
10년 전 조회 1,518
10년 전 조회 1,403
10년 전 조회 1,733
10년 전 조회 1,429
10년 전 조회 1,445
10년 전 조회 1,349
10년 전 조회 1,325
10년 전 조회 1,624
10년 전 조회 1,548
10년 전 조회 1,354
10년 전 조회 1,463
10년 전 조회 1,606
10년 전 조회 1,318
10년 전 조회 1,383
10년 전 조회 1,328
10년 전 조회 1,807
10년 전 조회 1,484
10년 전 조회 1,516
10년 전 조회 1,418
10년 전 조회 1,527
10년 전 조회 1,746
10년 전 조회 1,623
10년 전 조회 1,556
10년 전 조회 1,508
10년 전 조회 1,549
10년 전 조회 1,538
10년 전 조회 1,482
10년 전 조회 1,944
10년 전 조회 1,461
10년 전 조회 1,443
10년 전 조회 1,699
10년 전 조회 1,476
10년 전 조회 1,507
10년 전 조회 1,362
10년 전 조회 1,634
10년 전 조회 1,437
10년 전 조회 1,346
10년 전 조회 1,460
10년 전 조회 2,101
10년 전 조회 1,447
10년 전 조회 1,426
10년 전 조회 1,494
10년 전 조회 1,557
10년 전 조회 2,027
10년 전 조회 1,613
10년 전 조회 1,470
10년 전 조회 1,367
10년 전 조회 1,397
10년 전 조회 1,507
10년 전 조회 1,446
10년 전 조회 1,499
10년 전 조회 1,400
10년 전 조회 1,548
10년 전 조회 1,417
10년 전 조회 1,392
10년 전 조회 1,339
10년 전 조회 2,004
10년 전 조회 1,508
10년 전 조회 1,402
10년 전 조회 1,424
10년 전 조회 1,413
10년 전 조회 1,427
10년 전 조회 1,410
10년 전 조회 1,923
10년 전 조회 1,383
10년 전 조회 1,436
10년 전 조회 1,314
10년 전 조회 1,913
10년 전 조회 1,498
10년 전 조회 1,494
10년 전 조회 1,535
10년 전 조회 1,470
10년 전 조회 1,488