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년 전 조회 458
10년 전 조회 417
10년 전 조회 387
10년 전 조회 394
10년 전 조회 434
10년 전 조회 489
10년 전 조회 447
10년 전 조회 505
10년 전 조회 427
10년 전 조회 442
10년 전 조회 431
10년 전 조회 477
10년 전 조회 566
10년 전 조회 656
10년 전 조회 437
10년 전 조회 509
10년 전 조회 431
10년 전 조회 362
10년 전 조회 364
10년 전 조회 542
10년 전 조회 432
10년 전 조회 416
10년 전 조회 410
10년 전 조회 561
10년 전 조회 564
10년 전 조회 1,082
10년 전 조회 468
10년 전 조회 540
10년 전 조회 441
10년 전 조회 799
10년 전 조회 517
10년 전 조회 505
10년 전 조회 478
10년 전 조회 431
10년 전 조회 672
10년 전 조회 571
10년 전 조회 395
10년 전 조회 492
10년 전 조회 619
10년 전 조회 345
10년 전 조회 406
10년 전 조회 409
10년 전 조회 845
10년 전 조회 527
10년 전 조회 535
10년 전 조회 562
10년 전 조회 540
10년 전 조회 768
10년 전 조회 628
10년 전 조회 576
10년 전 조회 579
10년 전 조회 574
10년 전 조회 558
10년 전 조회 488
10년 전 조회 968
10년 전 조회 475
10년 전 조회 500
10년 전 조회 716
10년 전 조회 503
10년 전 조회 559
10년 전 조회 418
10년 전 조회 683
10년 전 조회 505
10년 전 조회 444
10년 전 조회 445
10년 전 조회 1,136
10년 전 조회 516
10년 전 조회 505
10년 전 조회 477
10년 전 조회 629
10년 전 조회 1,067
10년 전 조회 670
10년 전 조회 522
10년 전 조회 458
10년 전 조회 495
10년 전 조회 550
10년 전 조회 477
10년 전 조회 543
10년 전 조회 460
10년 전 조회 595
10년 전 조회 486
10년 전 조회 480
10년 전 조회 437
10년 전 조회 1,053
10년 전 조회 529
10년 전 조회 487
10년 전 조회 501
10년 전 조회 475
10년 전 조회 516
10년 전 조회 491
10년 전 조회 995
10년 전 조회 433
10년 전 조회 478
10년 전 조회 384
10년 전 조회 986
10년 전 조회 538
10년 전 조회 519
10년 전 조회 591
10년 전 조회 543
10년 전 조회 597
🐛 버그신고