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년 전 조회 900
10년 전 조회 858
10년 전 조회 840
10년 전 조회 820
10년 전 조회 845
10년 전 조회 942
10년 전 조회 891
10년 전 조회 987
10년 전 조회 855
10년 전 조회 895
10년 전 조회 883
10년 전 조회 929
10년 전 조회 1,087
10년 전 조회 1,093
10년 전 조회 883
10년 전 조회 959
10년 전 조회 861
10년 전 조회 810
10년 전 조회 844
10년 전 조회 974
10년 전 조회 874
10년 전 조회 873
10년 전 조회 857
10년 전 조회 1,038
10년 전 조회 1,007
10년 전 조회 1,501
10년 전 조회 908
10년 전 조회 1,004
10년 전 조회 923
10년 전 조회 1,257
10년 전 조회 940
10년 전 조회 945
10년 전 조회 894
10년 전 조회 871
10년 전 조회 1,139
10년 전 조회 1,041
10년 전 조회 848
10년 전 조회 956
10년 전 조회 1,099
10년 전 조회 810
10년 전 조회 874
10년 전 조회 869
10년 전 조회 1,301
10년 전 조회 1,064
10년 전 조회 1,077
10년 전 조회 958
10년 전 조회 1,078
10년 전 조회 1,292
10년 전 조회 1,196
10년 전 조회 1,132
10년 전 조회 1,077
10년 전 조회 1,117
10년 전 조회 1,122
10년 전 조회 1,043
10년 전 조회 1,436
10년 전 조회 944
10년 전 조회 960
10년 전 조회 1,201
10년 전 조회 969
10년 전 조회 1,018
10년 전 조회 861
10년 전 조회 1,144
10년 전 조회 947
10년 전 조회 845
10년 전 조회 910
10년 전 조회 1,613
10년 전 조회 956
10년 전 조회 962
10년 전 조회 941
10년 전 조회 1,091
10년 전 조회 1,537
10년 전 조회 1,192
10년 전 조회 968
10년 전 조회 878
10년 전 조회 948
10년 전 조회 1,026
10년 전 조회 928
10년 전 조회 1,001
10년 전 조회 907
10년 전 조회 1,087
10년 전 조회 939
10년 전 조회 914
10년 전 조회 877
10년 전 조회 1,513
10년 전 조회 1,008
10년 전 조회 960
10년 전 조회 970
10년 전 조회 973
10년 전 조회 971
10년 전 조회 1,003
10년 전 조회 1,470
10년 전 조회 919
10년 전 조회 976
10년 전 조회 871
10년 전 조회 1,447
10년 전 조회 1,100
10년 전 조회 1,083
10년 전 조회 1,157
10년 전 조회 1,097
10년 전 조회 1,050