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년 전 조회 875
10년 전 조회 817
10년 전 조회 818
10년 전 조회 788
10년 전 조회 816
10년 전 조회 919
10년 전 조회 859
10년 전 조회 967
10년 전 조회 833
10년 전 조회 876
10년 전 조회 848
10년 전 조회 906
10년 전 조회 1,072
10년 전 조회 1,067
10년 전 조회 859
10년 전 조회 943
10년 전 조회 833
10년 전 조회 788
10년 전 조회 812
10년 전 조회 950
10년 전 조회 865
10년 전 조회 854
10년 전 조회 840
10년 전 조회 1,008
10년 전 조회 982
10년 전 조회 1,482
10년 전 조회 892
10년 전 조회 981
10년 전 조회 899
10년 전 조회 1,239
10년 전 조회 914
10년 전 조회 927
10년 전 조회 877
10년 전 조회 842
10년 전 조회 1,119
10년 전 조회 1,023
10년 전 조회 830
10년 전 조회 939
10년 전 조회 1,075
10년 전 조회 779
10년 전 조회 858
10년 전 조회 833
10년 전 조회 1,283
10년 전 조회 1,049
10년 전 조회 1,073
10년 전 조회 942
10년 전 조회 1,060
10년 전 조회 1,272
10년 전 조회 1,172
10년 전 조회 1,116
10년 전 조회 1,062
10년 전 조회 1,100
10년 전 조회 1,113
10년 전 조회 1,033
10년 전 조회 1,417
10년 전 조회 923
10년 전 조회 930
10년 전 조회 1,183
10년 전 조회 950
10년 전 조회 1,000
10년 전 조회 843
10년 전 조회 1,129
10년 전 조회 930
10년 전 조회 822
10년 전 조회 895
10년 전 조회 1,599
10년 전 조회 930
10년 전 조회 938
10년 전 조회 925
10년 전 조회 1,076
10년 전 조회 1,509
10년 전 조회 1,175
10년 전 조회 953
10년 전 조회 853
10년 전 조회 933
10년 전 조회 1,004
10년 전 조회 915
10년 전 조회 986
10년 전 조회 890
10년 전 조회 1,064
10년 전 조회 921
10년 전 조회 886
10년 전 조회 864
10년 전 조회 1,501
10년 전 조회 993
10년 전 조회 946
10년 전 조회 946
10년 전 조회 956
10년 전 조회 948
10년 전 조회 977
10년 전 조회 1,441
10년 전 조회 899
10년 전 조회 952
10년 전 조회 846
10년 전 조회 1,428
10년 전 조회 1,078
10년 전 조회 1,070
10년 전 조회 1,139
10년 전 조회 1,080
10년 전 조회 1,036