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,340
10년 전 조회 1,287
10년 전 조회 1,254
10년 전 조회 1,245
10년 전 조회 1,280
10년 전 조회 1,350
10년 전 조회 1,299
10년 전 조회 1,383
10년 전 조회 1,293
10년 전 조회 1,339
10년 전 조회 1,318
10년 전 조회 1,383
10년 전 조회 1,456
10년 전 조회 1,526
10년 전 조회 1,323
10년 전 조회 1,382
10년 전 조회 1,280
10년 전 조회 1,198
10년 전 조회 1,246
10년 전 조회 1,371
10년 전 조회 1,294
10년 전 조회 1,296
10년 전 조회 1,278
10년 전 조회 1,440
10년 전 조회 1,401
10년 전 조회 1,907
10년 전 조회 1,303
10년 전 조회 1,423
10년 전 조회 1,309
10년 전 조회 1,643
10년 전 조회 1,341
10년 전 조회 1,349
10년 전 조회 1,253
10년 전 조회 1,255
10년 전 조회 1,560
10년 전 조회 1,458
10년 전 조회 1,267
10년 전 조회 1,372
10년 전 조회 1,532
10년 전 조회 1,231
10년 전 조회 1,287
10년 전 조회 1,238
10년 전 조회 1,723
10년 전 조회 1,395
10년 전 조회 1,432
10년 전 조회 1,335
10년 전 조회 1,450
10년 전 조회 1,668
10년 전 조회 1,539
10년 전 조회 1,480
10년 전 조회 1,435
10년 전 조회 1,462
10년 전 조회 1,445
10년 전 조회 1,393
10년 전 조회 1,863
10년 전 조회 1,383
10년 전 조회 1,364
10년 전 조회 1,606
10년 전 조회 1,397
10년 전 조회 1,423
10년 전 조회 1,274
10년 전 조회 1,546
10년 전 조회 1,354
10년 전 조회 1,270
10년 전 조회 1,376
10년 전 조회 2,010
10년 전 조회 1,376
10년 전 조회 1,357
10년 전 조회 1,405
10년 전 조회 1,477
10년 전 조회 1,952
10년 전 조회 1,547
10년 전 조회 1,396
10년 전 조회 1,296
10년 전 조회 1,322
10년 전 조회 1,434
10년 전 조회 1,359
10년 전 조회 1,426
10년 전 조회 1,322
10년 전 조회 1,497
10년 전 조회 1,342
10년 전 조회 1,315
10년 전 조회 1,266
10년 전 조회 1,935
10년 전 조회 1,431
10년 전 조회 1,335
10년 전 조회 1,354
10년 전 조회 1,346
10년 전 조회 1,375
10년 전 조회 1,339
10년 전 조회 1,850
10년 전 조회 1,321
10년 전 조회 1,369
10년 전 조회 1,262
10년 전 조회 1,845
10년 전 조회 1,425
10년 전 조회 1,430
10년 전 조회 1,459
10년 전 조회 1,411
10년 전 조회 1,410