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,134
10년 전 조회 1,079
10년 전 조회 1,059
10년 전 조회 1,059
10년 전 조회 1,084
10년 전 조회 1,183
10년 전 조회 1,120
10년 전 조회 1,206
10년 전 조회 1,093
10년 전 조회 1,121
10년 전 조회 1,111
10년 전 조회 1,171
10년 전 조회 1,263
10년 전 조회 1,340
10년 전 조회 1,138
10년 전 조회 1,210
10년 전 조회 1,098
10년 전 조회 1,018
10년 전 조회 1,074
10년 전 조회 1,207
10년 전 조회 1,098
10년 전 조회 1,111
10년 전 조회 1,105
10년 전 조회 1,245
10년 전 조회 1,231
10년 전 조회 1,744
10년 전 조회 1,134
10년 전 조회 1,242
10년 전 조회 1,135
10년 전 조회 1,460
10년 전 조회 1,174
10년 전 조회 1,154
10년 전 조회 1,088
10년 전 조회 1,078
10년 전 조회 1,373
10년 전 조회 1,268
10년 전 조회 1,080
10년 전 조회 1,186
10년 전 조회 1,347
10년 전 조회 1,065
10년 전 조회 1,105
10년 전 조회 1,088
10년 전 조회 1,541
10년 전 조회 1,236
10년 전 조회 1,256
10년 전 조회 1,183
10년 전 조회 1,307
10년 전 조회 1,497
10년 전 조회 1,393
10년 전 조회 1,317
10년 전 조회 1,278
10년 전 조회 1,306
10년 전 조회 1,278
10년 전 조회 1,224
10년 전 조회 1,696
10년 전 조회 1,196
10년 전 조회 1,214
10년 전 조회 1,420
10년 전 조회 1,230
10년 전 조회 1,260
10년 전 조회 1,098
10년 전 조회 1,364
10년 전 조회 1,189
10년 전 조회 1,118
10년 전 조회 1,167
10년 전 조회 1,852
10년 전 조회 1,190
10년 전 조회 1,194
10년 전 조회 1,194
10년 전 조회 1,306
10년 전 조회 1,797
10년 전 조회 1,383
10년 전 조회 1,201
10년 전 조회 1,141
10년 전 조회 1,179
10년 전 조회 1,278
10년 전 조회 1,179
10년 전 조회 1,248
10년 전 조회 1,174
10년 전 조회 1,344
10년 전 조회 1,191
10년 전 조회 1,169
10년 전 조회 1,099
10년 전 조회 1,750
10년 전 조회 1,255
10년 전 조회 1,182
10년 전 조회 1,212
10년 전 조회 1,203
10년 전 조회 1,224
10년 전 조회 1,198
10년 전 조회 1,705
10년 전 조회 1,147
10년 전 조회 1,235
10년 전 조회 1,107
10년 전 조회 1,685
10년 전 조회 1,282
10년 전 조회 1,275
10년 전 조회 1,319
10년 전 조회 1,260
10년 전 조회 1,268