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,212
10년 전 조회 1,175
10년 전 조회 1,142
10년 전 조회 1,147
10년 전 조회 1,162
10년 전 조회 1,257
10년 전 조회 1,199
10년 전 조회 1,277
10년 전 조회 1,179
10년 전 조회 1,207
10년 전 조회 1,203
10년 전 조회 1,257
10년 전 조회 1,350
10년 전 조회 1,428
10년 전 조회 1,222
10년 전 조회 1,288
10년 전 조회 1,166
10년 전 조회 1,091
10년 전 조회 1,146
10년 전 조회 1,284
10년 전 조회 1,183
10년 전 조회 1,197
10년 전 조회 1,185
10년 전 조회 1,327
10년 전 조회 1,306
10년 전 조회 1,823
10년 전 조회 1,206
10년 전 조회 1,320
10년 전 조회 1,203
10년 전 조회 1,541
10년 전 조회 1,245
10년 전 조회 1,236
10년 전 조회 1,155
10년 전 조회 1,147
10년 전 조회 1,448
10년 전 조회 1,356
10년 전 조회 1,151
10년 전 조회 1,282
10년 전 조회 1,432
10년 전 조회 1,131
10년 전 조회 1,197
10년 전 조회 1,155
10년 전 조회 1,624
10년 전 조회 1,313
10년 전 조회 1,343
10년 전 조회 1,256
10년 전 조회 1,368
10년 전 조회 1,576
10년 전 조회 1,449
10년 전 조회 1,407
10년 전 조회 1,348
10년 전 조회 1,383
10년 전 조회 1,365
10년 전 조회 1,308
10년 전 조회 1,779
10년 전 조회 1,294
10년 전 조회 1,290
10년 전 조회 1,508
10년 전 조회 1,311
10년 전 조회 1,359
10년 전 조회 1,186
10년 전 조회 1,461
10년 전 조회 1,276
10년 전 조회 1,197
10년 전 조회 1,271
10년 전 조회 1,925
10년 전 조회 1,293
10년 전 조회 1,286
10년 전 조회 1,303
10년 전 조회 1,405
10년 전 조회 1,871
10년 전 조회 1,465
10년 전 조회 1,296
10년 전 조회 1,216
10년 전 조회 1,251
10년 전 조회 1,358
10년 전 조회 1,267
10년 전 조회 1,338
10년 전 조회 1,238
10년 전 조회 1,431
10년 전 조회 1,272
10년 전 조회 1,245
10년 전 조회 1,182
10년 전 조회 1,843
10년 전 조회 1,341
10년 전 조회 1,259
10년 전 조회 1,284
10년 전 조회 1,275
10년 전 조회 1,298
10년 전 조회 1,266
10년 전 조회 1,778
10년 전 조회 1,238
10년 전 조회 1,306
10년 전 조회 1,189
10년 전 조회 1,769
10년 전 조회 1,353
10년 전 조회 1,363
10년 전 조회 1,405
10년 전 조회 1,342
10년 전 조회 1,363