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,422
10년 전 조회 1,362
10년 전 조회 1,340
10년 전 조회 1,332
10년 전 조회 1,356
10년 전 조회 1,455
10년 전 조회 1,377
10년 전 조회 1,463
10년 전 조회 1,378
10년 전 조회 1,426
10년 전 조회 1,412
10년 전 조회 1,473
10년 전 조회 1,537
10년 전 조회 1,608
10년 전 조회 1,417
10년 전 조회 1,462
10년 전 조회 1,371
10년 전 조회 1,290
10년 전 조회 1,340
10년 전 조회 1,456
10년 전 조회 1,388
10년 전 조회 1,393
10년 전 조회 1,375
10년 전 조회 1,526
10년 전 조회 1,498
10년 전 조회 1,997
10년 전 조회 1,391
10년 전 조회 1,526
10년 전 조회 1,408
10년 전 조회 1,742
10년 전 조회 1,432
10년 전 조회 1,457
10년 전 조회 1,354
10년 전 조회 1,331
10년 전 조회 1,631
10년 전 조회 1,553
10년 전 조회 1,358
10년 전 조회 1,469
10년 전 조회 1,615
10년 전 조회 1,324
10년 전 조회 1,391
10년 전 조회 1,340
10년 전 조회 1,821
10년 전 조회 1,493
10년 전 조회 1,527
10년 전 조회 1,428
10년 전 조회 1,535
10년 전 조회 1,758
10년 전 조회 1,628
10년 전 조회 1,567
10년 전 조회 1,517
10년 전 조회 1,561
10년 전 조회 1,547
10년 전 조회 1,494
10년 전 조회 1,954
10년 전 조회 1,472
10년 전 조회 1,445
10년 전 조회 1,712
10년 전 조회 1,488
10년 전 조회 1,512
10년 전 조회 1,366
10년 전 조회 1,646
10년 전 조회 1,446
10년 전 조회 1,350
10년 전 조회 1,468
10년 전 조회 2,112
10년 전 조회 1,455
10년 전 조회 1,433
10년 전 조회 1,504
10년 전 조회 1,565
10년 전 조회 2,034
10년 전 조회 1,621
10년 전 조회 1,473
10년 전 조회 1,374
10년 전 조회 1,402
10년 전 조회 1,511
10년 전 조회 1,458
10년 전 조회 1,507
10년 전 조회 1,407
10년 전 조회 1,556
10년 전 조회 1,423
10년 전 조회 1,401
10년 전 조회 1,347
10년 전 조회 2,010
10년 전 조회 1,517
10년 전 조회 1,410
10년 전 조회 1,435
10년 전 조회 1,418
10년 전 조회 1,438
10년 전 조회 1,419
10년 전 조회 1,929
10년 전 조회 1,386
10년 전 조회 1,443
10년 전 조회 1,322
10년 전 조회 1,920
10년 전 조회 1,501
10년 전 조회 1,500
10년 전 조회 1,545
10년 전 조회 1,474
10년 전 조회 1,497