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,476
10년 전 조회 1,417
10년 전 조회 1,405
10년 전 조회 1,391
10년 전 조회 1,420
10년 전 조회 1,517
10년 전 조회 1,442
10년 전 조회 1,528
10년 전 조회 1,432
10년 전 조회 1,496
10년 전 조회 1,486
10년 전 조회 1,539
10년 전 조회 1,608
10년 전 조회 1,681
10년 전 조회 1,470
10년 전 조회 1,530
10년 전 조회 1,445
10년 전 조회 1,375
10년 전 조회 1,409
10년 전 조회 1,519
10년 전 조회 1,464
10년 전 조회 1,471
10년 전 조회 1,455
10년 전 조회 1,606
10년 전 조회 1,570
10년 전 조회 2,073
10년 전 조회 1,468
10년 전 조회 1,589
10년 전 조회 1,489
10년 전 조회 1,820
10년 전 조회 1,496
10년 전 조회 1,517
10년 전 조회 1,416
10년 전 조회 1,402
10년 전 조회 1,715
10년 전 조회 1,631
10년 전 조회 1,438
10년 전 조회 1,545
10년 전 조회 1,683
10년 전 조회 1,399
10년 전 조회 1,472
10년 전 조회 1,414
10년 전 조회 1,894
10년 전 조회 1,565
10년 전 조회 1,616
10년 전 조회 1,502
10년 전 조회 1,612
10년 전 조회 1,836
10년 전 조회 1,701
10년 전 조회 1,648
10년 전 조회 1,582
10년 전 조회 1,634
10년 전 조회 1,623
10년 전 조회 1,564
10년 전 조회 2,032
10년 전 조회 1,571
10년 전 조회 1,521
10년 전 조회 1,786
10년 전 조회 1,570
10년 전 조회 1,597
10년 전 조회 1,462
10년 전 조회 1,711
10년 전 조회 1,538
10년 전 조회 1,419
10년 전 조회 1,540
10년 전 조회 2,185
10년 전 조회 1,520
10년 전 조회 1,503
10년 전 조회 1,591
10년 전 조회 1,641
10년 전 조회 2,109
10년 전 조회 1,689
10년 전 조회 1,553
10년 전 조회 1,450
10년 전 조회 1,483
10년 전 조회 1,580
10년 전 조회 1,534
10년 전 조회 1,595
10년 전 조회 1,490
10년 전 조회 1,631
10년 전 조회 1,496
10년 전 조회 1,475
10년 전 조회 1,428
10년 전 조회 2,086
10년 전 조회 1,599
10년 전 조회 1,492
10년 전 조회 1,498
10년 전 조회 1,496
10년 전 조회 1,502
10년 전 조회 1,481
10년 전 조회 1,996
10년 전 조회 1,450
10년 전 조회 1,515
10년 전 조회 1,393
10년 전 조회 1,991
10년 전 조회 1,573
10년 전 조회 1,561
10년 전 조회 1,617
10년 전 조회 1,535
10년 전 조회 1,565