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,266
10년 전 조회 1,227
10년 전 조회 1,190
10년 전 조회 1,188
10년 전 조회 1,212
10년 전 조회 1,298
10년 전 조회 1,236
10년 전 조회 1,325
10년 전 조회 1,228
10년 전 조회 1,266
10년 전 조회 1,255
10년 전 조회 1,300
10년 전 조회 1,401
10년 전 조회 1,472
10년 전 조회 1,271
10년 전 조회 1,337
10년 전 조회 1,219
10년 전 조회 1,147
10년 전 조회 1,196
10년 전 조회 1,327
10년 전 조회 1,228
10년 전 조회 1,243
10년 전 조회 1,227
10년 전 조회 1,377
10년 전 조회 1,358
10년 전 조회 1,861
10년 전 조회 1,247
10년 전 조회 1,361
10년 전 조회 1,251
10년 전 조회 1,582
10년 전 조회 1,284
10년 전 조회 1,292
10년 전 조회 1,203
10년 전 조회 1,196
10년 전 조회 1,491
10년 전 조회 1,408
10년 전 조회 1,201
10년 전 조회 1,321
10년 전 조회 1,478
10년 전 조회 1,173
10년 전 조회 1,234
10년 전 조회 1,190
10년 전 조회 1,672
10년 전 조회 1,356
10년 전 조회 1,380
10년 전 조회 1,292
10년 전 조회 1,403
10년 전 조회 1,617
10년 전 조회 1,498
10년 전 조회 1,440
10년 전 조회 1,388
10년 전 조회 1,416
10년 전 조회 1,399
10년 전 조회 1,348
10년 전 조회 1,819
10년 전 조회 1,334
10년 전 조회 1,324
10년 전 조회 1,553
10년 전 조회 1,345
10년 전 조회 1,388
10년 전 조회 1,214
10년 전 조회 1,496
10년 전 조회 1,316
10년 전 조회 1,230
10년 전 조회 1,316
10년 전 조회 1,959
10년 전 조회 1,323
10년 전 조회 1,311
10년 전 조회 1,350
10년 전 조회 1,432
10년 전 조회 1,905
10년 전 조회 1,500
10년 전 조회 1,341
10년 전 조회 1,250
10년 전 조회 1,280
10년 전 조회 1,398
10년 전 조회 1,312
10년 전 조회 1,381
10년 전 조회 1,280
10년 전 조회 1,458
10년 전 조회 1,305
10년 전 조회 1,282
10년 전 조회 1,219
10년 전 조회 1,890
10년 전 조회 1,377
10년 전 조회 1,293
10년 전 조회 1,310
10년 전 조회 1,304
10년 전 조회 1,338
10년 전 조회 1,302
10년 전 조회 1,806
10년 전 조회 1,267
10년 전 조회 1,328
10년 전 조회 1,224
10년 전 조회 1,805
10년 전 조회 1,386
10년 전 조회 1,399
10년 전 조회 1,432
10년 전 조회 1,368
10년 전 조회 1,380