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,228
10년 전 조회 1,194
10년 전 조회 1,162
10년 전 조회 1,166
10년 전 조회 1,176
10년 전 조회 1,271
10년 전 조회 1,210
10년 전 조회 1,298
10년 전 조회 1,201
10년 전 조회 1,232
10년 전 조회 1,224
10년 전 조회 1,269
10년 전 조회 1,370
10년 전 조회 1,449
10년 전 조회 1,241
10년 전 조회 1,309
10년 전 조회 1,188
10년 전 조회 1,108
10년 전 조회 1,160
10년 전 조회 1,298
10년 전 조회 1,198
10년 전 조회 1,213
10년 전 조회 1,203
10년 전 조회 1,348
10년 전 조회 1,330
10년 전 조회 1,842
10년 전 조회 1,222
10년 전 조회 1,337
10년 전 조회 1,222
10년 전 조회 1,549
10년 전 조회 1,263
10년 전 조회 1,258
10년 전 조회 1,166
10년 전 조회 1,163
10년 전 조회 1,463
10년 전 조회 1,374
10년 전 조회 1,176
10년 전 조회 1,303
10년 전 조회 1,453
10년 전 조회 1,152
10년 전 조회 1,207
10년 전 조회 1,168
10년 전 조회 1,643
10년 전 조회 1,328
10년 전 조회 1,360
10년 전 조회 1,267
10년 전 조회 1,379
10년 전 조회 1,592
10년 전 조회 1,473
10년 전 조회 1,420
10년 전 조회 1,365
10년 전 조회 1,397
10년 전 조회 1,375
10년 전 조회 1,320
10년 전 조회 1,790
10년 전 조회 1,308
10년 전 조회 1,302
10년 전 조회 1,527
10년 전 조회 1,323
10년 전 조회 1,370
10년 전 조회 1,198
10년 전 조회 1,471
10년 전 조회 1,293
10년 전 조회 1,213
10년 전 조회 1,286
10년 전 조회 1,935
10년 전 조회 1,309
10년 전 조회 1,294
10년 전 조회 1,324
10년 전 조회 1,419
10년 전 조회 1,884
10년 전 조회 1,481
10년 전 조회 1,316
10년 전 조회 1,230
10년 전 조회 1,265
10년 전 조회 1,367
10년 전 조회 1,287
10년 전 조회 1,353
10년 전 조회 1,261
10년 전 조회 1,435
10년 전 조회 1,284
10년 전 조회 1,260
10년 전 조회 1,197
10년 전 조회 1,871
10년 전 조회 1,355
10년 전 조회 1,265
10년 전 조회 1,290
10년 전 조회 1,286
10년 전 조회 1,309
10년 전 조회 1,279
10년 전 조회 1,789
10년 전 조회 1,247
10년 전 조회 1,313
10년 전 조회 1,203
10년 전 조회 1,779
10년 전 조회 1,367
10년 전 조회 1,373
10년 전 조회 1,416
10년 전 조회 1,351
10년 전 조회 1,367