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년 전 조회 601
10년 전 조회 558
10년 전 조회 539
10년 전 조회 530
10년 전 조회 557
10년 전 조회 636
10년 전 조회 589
10년 전 조회 666
10년 전 조회 568
10년 전 조회 592
10년 전 조회 583
10년 전 조회 627
10년 전 조회 715
10년 전 조회 812
10년 전 조회 576
10년 전 조회 656
10년 전 조회 560
10년 전 조회 516
10년 전 조회 514
10년 전 조회 673
10년 전 조회 572
10년 전 조회 562
10년 전 조회 562
10년 전 조회 727
10년 전 조회 722
10년 전 조회 1,220
10년 전 조회 600
10년 전 조회 688
10년 전 조회 597
10년 전 조회 942
10년 전 조회 651
10년 전 조회 653
10년 전 조회 596
10년 전 조회 570
10년 전 조회 820
10년 전 조회 734
10년 전 조회 547
10년 전 조회 648
10년 전 조회 773
10년 전 조회 478
10년 전 조회 557
10년 전 조회 542
10년 전 조회 1,003
10년 전 조회 673
10년 전 조회 708
10년 전 조회 664
10년 전 조회 667
10년 전 조회 905
10년 전 조회 799
10년 전 조회 738
10년 전 조회 700
10년 전 조회 712
10년 전 조회 708
10년 전 조회 649
10년 전 조회 1,116
10년 전 조회 633
10년 전 조회 643
10년 전 조회 864
10년 전 조회 649
10년 전 조회 706
10년 전 조회 559
10년 전 조회 828
10년 전 조회 644
10년 전 조회 546
10년 전 조회 600
10년 전 조회 1,290
10년 전 조회 658
10년 전 조회 653
10년 전 조회 639
10년 전 조회 793
10년 전 조회 1,206
10년 전 조회 800
10년 전 조회 671
10년 전 조회 589
10년 전 조회 641
10년 전 조회 693
10년 전 조회 640
10년 전 조회 703
10년 전 조회 616
10년 전 조회 750
10년 전 조회 633
10년 전 조회 608
10년 전 조회 582
10년 전 조회 1,221
10년 전 조회 692
10년 전 조회 635
10년 전 조회 643
10년 전 조회 632
10년 전 조회 666
10년 전 조회 647
10년 전 조회 1,128
10년 전 조회 588
10년 전 조회 626
10년 전 조회 541
10년 전 조회 1,129
10년 전 조회 681
10년 전 조회 685
10년 전 조회 742
10년 전 조회 693
10년 전 조회 746