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,390
10년 전 조회 1,334
10년 전 조회 1,302
10년 전 조회 1,295
10년 전 조회 1,324
10년 전 조회 1,408
10년 전 조회 1,343
10년 전 조회 1,425
10년 전 조회 1,346
10년 전 조회 1,388
10년 전 조회 1,370
10년 전 조회 1,433
10년 전 조회 1,506
10년 전 조회 1,569
10년 전 조회 1,373
10년 전 조회 1,426
10년 전 조회 1,325
10년 전 조회 1,246
10년 전 조회 1,290
10년 전 조회 1,425
10년 전 조회 1,345
10년 전 조회 1,351
10년 전 조회 1,331
10년 전 조회 1,491
10년 전 조회 1,463
10년 전 조회 1,957
10년 전 조회 1,352
10년 전 조회 1,482
10년 전 조회 1,374
10년 전 조회 1,693
10년 전 조회 1,390
10년 전 조회 1,414
10년 전 조회 1,304
10년 전 조회 1,297
10년 전 조회 1,600
10년 전 조회 1,509
10년 전 조회 1,315
10년 전 조회 1,423
10년 전 조회 1,575
10년 전 조회 1,287
10년 전 조회 1,346
10년 전 조회 1,293
10년 전 조회 1,780
10년 전 조회 1,447
10년 전 조회 1,485
10년 전 조회 1,388
10년 전 조회 1,503
10년 전 조회 1,718
10년 전 조회 1,586
10년 전 조회 1,528
10년 전 조회 1,482
10년 전 조회 1,516
10년 전 조회 1,499
10년 전 조회 1,451
10년 전 조회 1,909
10년 전 조회 1,431
10년 전 조회 1,408
10년 전 조회 1,664
10년 전 조회 1,443
10년 전 조회 1,475
10년 전 조회 1,334
10년 전 조회 1,605
10년 전 조회 1,401
10년 전 조회 1,316
10년 전 조회 1,429
10년 전 조회 2,075
10년 전 조회 1,419
10년 전 조회 1,397
10년 전 조회 1,457
10년 전 조회 1,527
10년 전 조회 2,000
10년 전 조회 1,588
10년 전 조회 1,441
10년 전 조회 1,340
10년 전 조회 1,362
10년 전 조회 1,477
10년 전 조회 1,416
10년 전 조회 1,475
10년 전 조회 1,370
10년 전 조회 1,532
10년 전 조회 1,394
10년 전 조회 1,369
10년 전 조회 1,315
10년 전 조회 1,983
10년 전 조회 1,481
10년 전 조회 1,378
10년 전 조회 1,405
10년 전 조회 1,390
10년 전 조회 1,403
10년 전 조회 1,385
10년 전 조회 1,891
10년 전 조회 1,356
10년 전 조회 1,412
10년 전 조회 1,298
10년 전 조회 1,890
10년 전 조회 1,472
10년 전 조회 1,464
10년 전 조회 1,505
10년 전 조회 1,446
10년 전 조회 1,458