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년 전 조회 472
10년 전 조회 427
10년 전 조회 400
10년 전 조회 406
10년 전 조회 445
10년 전 조회 503
10년 전 조회 457
10년 전 조회 518
10년 전 조회 438
10년 전 조회 450
10년 전 조회 447
10년 전 조회 487
10년 전 조회 576
10년 전 조회 670
10년 전 조회 453
10년 전 조회 522
10년 전 조회 442
10년 전 조회 372
10년 전 조회 377
10년 전 조회 556
10년 전 조회 444
10년 전 조회 430
10년 전 조회 421
10년 전 조회 572
10년 전 조회 576
10년 전 조회 1,091
10년 전 조회 480
10년 전 조회 553
10년 전 조회 462
10년 전 조회 809
10년 전 조회 532
10년 전 조회 513
10년 전 조회 490
10년 전 조회 441
10년 전 조회 685
10년 전 조회 582
10년 전 조회 410
10년 전 조회 502
10년 전 조회 633
10년 전 조회 357
10년 전 조회 414
10년 전 조회 420
10년 전 조회 858
10년 전 조회 538
10년 전 조회 546
10년 전 조회 572
10년 전 조회 556
10년 전 조회 781
10년 전 조회 650
10년 전 조회 591
10년 전 조회 592
10년 전 조회 585
10년 전 조회 572
10년 전 조회 503
10년 전 조회 980
10년 전 조회 488
10년 전 조회 515
10년 전 조회 728
10년 전 조회 511
10년 전 조회 574
10년 전 조회 426
10년 전 조회 701
10년 전 조회 515
10년 전 조회 458
10년 전 조회 454
10년 전 조회 1,146
10년 전 조회 528
10년 전 조회 524
10년 전 조회 484
10년 전 조회 641
10년 전 조회 1,084
10년 전 조회 685
10년 전 조회 530
10년 전 조회 472
10년 전 조회 509
10년 전 조회 561
10년 전 조회 495
10년 전 조회 551
10년 전 조회 475
10년 전 조회 611
10년 전 조회 504
10년 전 조회 492
10년 전 조회 450
10년 전 조회 1,071
10년 전 조회 545
10년 전 조회 493
10년 전 조회 509
10년 전 조회 491
10년 전 조회 530
10년 전 조회 502
10년 전 조회 1,010
10년 전 조회 447
10년 전 조회 498
10년 전 조회 398
10년 전 조회 997
10년 전 조회 553
10년 전 조회 533
10년 전 조회 603
10년 전 조회 554
10년 전 조회 611
🐛 버그신고