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,246
10년 전 조회 1,211
10년 전 조회 1,171
10년 전 조회 1,175
10년 전 조회 1,195
10년 전 조회 1,284
10년 전 조회 1,221
10년 전 조회 1,305
10년 전 조회 1,210
10년 전 조회 1,245
10년 전 조회 1,241
10년 전 조회 1,282
10년 전 조회 1,382
10년 전 조회 1,458
10년 전 조회 1,254
10년 전 조회 1,323
10년 전 조회 1,199
10년 전 조회 1,125
10년 전 조회 1,178
10년 전 조회 1,316
10년 전 조회 1,212
10년 전 조회 1,227
10년 전 조회 1,213
10년 전 조회 1,357
10년 전 조회 1,347
10년 전 조회 1,850
10년 전 조회 1,231
10년 전 조회 1,350
10년 전 조회 1,229
10년 전 조회 1,562
10년 전 조회 1,272
10년 전 조회 1,272
10년 전 조회 1,182
10년 전 조회 1,177
10년 전 조회 1,481
10년 전 조회 1,388
10년 전 조회 1,187
10년 전 조회 1,309
10년 전 조회 1,465
10년 전 조회 1,163
10년 전 조회 1,219
10년 전 조회 1,178
10년 전 조회 1,654
10년 전 조회 1,343
10년 전 조회 1,371
10년 전 조회 1,278
10년 전 조회 1,389
10년 전 조회 1,606
10년 전 조회 1,487
10년 전 조회 1,428
10년 전 조회 1,368
10년 전 조회 1,409
10년 전 조회 1,388
10년 전 조회 1,333
10년 전 조회 1,800
10년 전 조회 1,318
10년 전 조회 1,311
10년 전 조회 1,537
10년 전 조회 1,329
10년 전 조회 1,377
10년 전 조회 1,203
10년 전 조회 1,485
10년 전 조회 1,307
10년 전 조회 1,221
10년 전 조회 1,298
10년 전 조회 1,947
10년 전 조회 1,311
10년 전 조회 1,300
10년 전 조회 1,331
10년 전 조회 1,427
10년 전 조회 1,892
10년 전 조회 1,487
10년 전 조회 1,323
10년 전 조회 1,239
10년 전 조회 1,274
10년 전 조회 1,381
10년 전 조회 1,296
10년 전 조회 1,362
10년 전 조회 1,265
10년 전 조회 1,443
10년 전 조회 1,293
10년 전 조회 1,269
10년 전 조회 1,209
10년 전 조회 1,880
10년 전 조회 1,366
10년 전 조회 1,282
10년 전 조회 1,296
10년 전 조회 1,290
10년 전 조회 1,320
10년 전 조회 1,286
10년 전 조회 1,798
10년 전 조회 1,258
10년 전 조회 1,318
10년 전 조회 1,209
10년 전 조회 1,792
10년 전 조회 1,374
10년 전 조회 1,385
10년 전 조회 1,424
10년 전 조회 1,356
10년 전 조회 1,372