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년 전 조회 721
10년 전 조회 691
10년 전 조회 668
10년 전 조회 647
10년 전 조회 683
10년 전 조회 769
10년 전 조회 709
10년 전 조회 809
10년 전 조회 699
10년 전 조회 728
10년 전 조회 700
10년 전 조회 764
10년 전 조회 842
10년 전 조회 928
10년 전 조회 701
10년 전 조회 797
10년 전 조회 700
10년 전 조회 651
10년 전 조회 653
10년 전 조회 812
10년 전 조회 723
10년 전 조회 695
10년 전 조회 699
10년 전 조회 865
10년 전 조회 839
10년 전 조회 1,350
10년 전 조회 742
10년 전 조회 817
10년 전 조회 731
10년 전 조회 1,080
10년 전 조회 770
10년 전 조회 785
10년 전 조회 717
10년 전 조회 706
10년 전 조회 949
10년 전 조회 872
10년 전 조회 685
10년 전 조회 772
10년 전 조회 907
10년 전 조회 625
10년 전 조회 700
10년 전 조회 688
10년 전 조회 1,132
10년 전 조회 796
10년 전 조회 831
10년 전 조회 789
10년 전 조회 792
10년 전 조회 1,035
10년 전 조회 924
10년 전 조회 887
10년 전 조회 828
10년 전 조회 858
10년 전 조회 850
10년 전 조회 775
10년 전 조회 1,251
10년 전 조회 770
10년 전 조회 761
10년 전 조회 1,001
10년 전 조회 777
10년 전 조회 833
10년 전 조회 689
10년 전 조회 959
10년 전 조회 763
10년 전 조회 675
10년 전 조회 740
10년 전 조회 1,418
10년 전 조회 782
10년 전 조회 775
10년 전 조회 770
10년 전 조회 933
10년 전 조회 1,338
10년 전 조회 937
10년 전 조회 798
10년 전 조회 725
10년 전 조회 762
10년 전 조회 825
10년 전 조회 762
10년 전 조회 829
10년 전 조회 736
10년 전 조회 899
10년 전 조회 757
10년 전 조회 720
10년 전 조회 693
10년 전 조회 1,345
10년 전 조회 823
10년 전 조회 775
10년 전 조회 773
10년 전 조회 764
10년 전 조회 780
10년 전 조회 789
10년 전 조회 1,253
10년 전 조회 719
10년 전 조회 768
10년 전 조회 674
10년 전 조회 1,259
10년 전 조회 803
10년 전 조회 800
10년 전 조회 870
10년 전 조회 819
10년 전 조회 872