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년 전 조회 481
10년 전 조회 434
10년 전 조회 407
10년 전 조회 409
10년 전 조회 447
10년 전 조회 512
10년 전 조회 464
10년 전 조회 529
10년 전 조회 442
10년 전 조회 458
10년 전 조회 454
10년 전 조회 493
10년 전 조회 582
10년 전 조회 678
10년 전 조회 462
10년 전 조회 527
10년 전 조회 447
10년 전 조회 384
10년 전 조회 387
10년 전 조회 564
10년 전 조회 452
10년 전 조회 435
10년 전 조회 428
10년 전 조회 578
10년 전 조회 587
10년 전 조회 1,097
10년 전 조회 488
10년 전 조회 559
10년 전 조회 471
10년 전 조회 815
10년 전 조회 542
10년 전 조회 522
10년 전 조회 497
10년 전 조회 443
10년 전 조회 693
10년 전 조회 589
10년 전 조회 418
10년 전 조회 506
10년 전 조회 645
10년 전 조회 362
10년 전 조회 416
10년 전 조회 436
10년 전 조회 864
10년 전 조회 545
10년 전 조회 552
10년 전 조회 574
10년 전 조회 564
10년 전 조회 786
10년 전 조회 657
10년 전 조회 600
10년 전 조회 598
10년 전 조회 593
10년 전 조회 577
10년 전 조회 509
10년 전 조회 989
10년 전 조회 493
10년 전 조회 523
10년 전 조회 737
10년 전 조회 516
10년 전 조회 580
10년 전 조회 431
10년 전 조회 711
10년 전 조회 520
10년 전 조회 465
10년 전 조회 459
10년 전 조회 1,158
10년 전 조회 537
10년 전 조회 529
10년 전 조회 487
10년 전 조회 648
10년 전 조회 1,086
10년 전 조회 692
10년 전 조회 535
10년 전 조회 478
10년 전 조회 513
10년 전 조회 569
10년 전 조회 501
10년 전 조회 565
10년 전 조회 480
10년 전 조회 625
10년 전 조회 511
10년 전 조회 500
10년 전 조회 457
10년 전 조회 1,077
10년 전 조회 551
10년 전 조회 501
10년 전 조회 519
10년 전 조회 498
10년 전 조회 537
10년 전 조회 513
10년 전 조회 1,014
10년 전 조회 455
10년 전 조회 508
10년 전 조회 401
10년 전 조회 1,006
10년 전 조회 563
10년 전 조회 538
10년 전 조회 612
10년 전 조회 565
10년 전 조회 624
🐛 버그신고