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년 전 조회 460
10년 전 조회 418
10년 전 조회 392
10년 전 조회 397
10년 전 조회 436
10년 전 조회 492
10년 전 조회 449
10년 전 조회 508
10년 전 조회 429
10년 전 조회 446
10년 전 조회 434
10년 전 조회 479
10년 전 조회 568
10년 전 조회 658
10년 전 조회 439
10년 전 조회 513
10년 전 조회 433
10년 전 조회 365
10년 전 조회 367
10년 전 조회 545
10년 전 조회 434
10년 전 조회 420
10년 전 조회 410
10년 전 조회 565
10년 전 조회 569
10년 전 조회 1,086
10년 전 조회 472
10년 전 조회 544
10년 전 조회 447
10년 전 조회 802
10년 전 조회 520
10년 전 조회 506
10년 전 조회 482
10년 전 조회 434
10년 전 조회 676
10년 전 조회 576
10년 전 조회 397
10년 전 조회 495
10년 전 조회 623
10년 전 조회 349
10년 전 조회 409
10년 전 조회 413
10년 전 조회 847
10년 전 조회 529
10년 전 조회 537
10년 전 조회 566
10년 전 조회 545
10년 전 조회 774
10년 전 조회 636
10년 전 조회 579
10년 전 조회 583
10년 전 조회 577
10년 전 조회 562
10년 전 조회 493
10년 전 조회 970
10년 전 조회 477
10년 전 조회 507
10년 전 조회 719
10년 전 조회 505
10년 전 조회 562
10년 전 조회 420
10년 전 조회 689
10년 전 조회 507
10년 전 조회 446
10년 전 조회 450
10년 전 조회 1,138
10년 전 조회 520
10년 전 조회 508
10년 전 조회 480
10년 전 조회 632
10년 전 조회 1,071
10년 전 조회 674
10년 전 조회 524
10년 전 조회 460
10년 전 조회 498
10년 전 조회 551
10년 전 조회 483
10년 전 조회 544
10년 전 조회 463
10년 전 조회 600
10년 전 조회 491
10년 전 조회 484
10년 전 조회 439
10년 전 조회 1,059
10년 전 조회 536
10년 전 조회 490
10년 전 조회 501
10년 전 조회 478
10년 전 조회 520
10년 전 조회 492
10년 전 조회 999
10년 전 조회 435
10년 전 조회 483
10년 전 조회 388
10년 전 조회 989
10년 전 조회 540
10년 전 조회 523
10년 전 조회 593
10년 전 조회 546
10년 전 조회 599
🐛 버그신고