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년 전 조회 941
10년 전 조회 906
10년 전 조회 892
10년 전 조회 880
10년 전 조회 907
10년 전 조회 1,003
10년 전 조회 939
10년 전 조회 1,025
10년 전 조회 905
10년 전 조회 941
10년 전 조회 926
10년 전 조회 980
10년 전 조회 1,123
10년 전 조회 1,145
10년 전 조회 948
10년 전 조회 1,018
10년 전 조회 915
10년 전 조회 851
10년 전 조회 895
10년 전 조회 1,024
10년 전 조회 924
10년 전 조회 924
10년 전 조회 890
10년 전 조회 1,082
10년 전 조회 1,059
10년 전 조회 1,542
10년 전 조회 953
10년 전 조회 1,047
10년 전 조회 961
10년 전 조회 1,306
10년 전 조회 996
10년 전 조회 986
10년 전 조회 937
10년 전 조회 915
10년 전 조회 1,174
10년 전 조회 1,089
10년 전 조회 893
10년 전 조회 1,000
10년 전 조회 1,142
10년 전 조회 860
10년 전 조회 922
10년 전 조회 913
10년 전 조회 1,343
10년 전 조회 1,092
10년 전 조회 1,107
10년 전 조회 1,000
10년 전 조회 1,117
10년 전 조회 1,322
10년 전 조회 1,234
10년 전 조회 1,160
10년 전 조회 1,120
10년 전 조회 1,138
10년 전 조회 1,149
10년 전 조회 1,072
10년 전 조회 1,478
10년 전 조회 993
10년 전 조회 1,007
10년 전 조회 1,245
10년 전 조회 1,016
10년 전 조회 1,068
10년 전 조회 902
10년 전 조회 1,174
10년 전 조회 1,000
10년 전 조회 895
10년 전 조회 964
10년 전 조회 1,662
10년 전 조회 1,006
10년 전 조회 1,014
10년 전 조회 986
10년 전 조회 1,143
10년 전 조회 1,590
10년 전 조회 1,228
10년 전 조회 1,011
10년 전 조회 932
10년 전 조회 1,002
10년 전 조회 1,072
10년 전 조회 974
10년 전 조회 1,051
10년 전 조회 962
10년 전 조회 1,133
10년 전 조회 989
10년 전 조회 974
10년 전 조회 926
10년 전 조회 1,556
10년 전 조회 1,060
10년 전 조회 999
10년 전 조회 1,016
10년 전 조회 1,017
10년 전 조회 1,017
10년 전 조회 1,050
10년 전 조회 1,516
10년 전 조회 964
10년 전 조회 1,037
10년 전 조회 928
10년 전 조회 1,492
10년 전 조회 1,129
10년 전 조회 1,117
10년 전 조회 1,183
10년 전 조회 1,126
10년 전 조회 1,095