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년 전 조회 1,498
10년 전 조회 1,440
10년 전 조회 1,433
10년 전 조회 1,417
10년 전 조회 1,445
10년 전 조회 1,548
10년 전 조회 1,466
10년 전 조회 1,554
10년 전 조회 1,459
10년 전 조회 1,523
10년 전 조회 1,510
10년 전 조회 1,568
10년 전 조회 1,632
10년 전 조회 1,703
10년 전 조회 1,501
10년 전 조회 1,562
10년 전 조회 1,468
10년 전 조회 1,403
10년 전 조회 1,443
10년 전 조회 1,550
10년 전 조회 1,490
10년 전 조회 1,497
10년 전 조회 1,474
10년 전 조회 1,640
10년 전 조회 1,603
10년 전 조회 2,104
10년 전 조회 1,497
10년 전 조회 1,613
10년 전 조회 1,512
10년 전 조회 1,848
10년 전 조회 1,525
10년 전 조회 1,546
10년 전 조회 1,438
10년 전 조회 1,430
10년 전 조회 1,745
10년 전 조회 1,658
10년 전 조회 1,463
10년 전 조회 1,574
10년 전 조회 1,719
10년 전 조회 1,424
10년 전 조회 1,507
10년 전 조회 1,440
10년 전 조회 1,926
10년 전 조회 1,598
10년 전 조회 1,654
10년 전 조회 1,529
10년 전 조회 1,640
10년 전 조회 1,857
10년 전 조회 1,738
10년 전 조회 1,683
10년 전 조회 1,617
10년 전 조회 1,657
10년 전 조회 1,654
10년 전 조회 1,603
10년 전 조회 2,060
10년 전 조회 1,602
10년 전 조회 1,545
10년 전 조회 1,814
10년 전 조회 1,601
10년 전 조회 1,634
10년 전 조회 1,497
10년 전 조회 1,754
10년 전 조회 1,573
10년 전 조회 1,457
10년 전 조회 1,576
10년 전 조회 2,216
10년 전 조회 1,562
10년 전 조회 1,531
10년 전 조회 1,623
10년 전 조회 1,675
10년 전 조회 2,149
10년 전 조회 1,726
10년 전 조회 1,595
10년 전 조회 1,482
10년 전 조회 1,515
10년 전 조회 1,622
10년 전 조회 1,573
10년 전 조회 1,626
10년 전 조회 1,533
10년 전 조회 1,664
10년 전 조회 1,522
10년 전 조회 1,510
10년 전 조회 1,459
10년 전 조회 2,116
10년 전 조회 1,635
10년 전 조회 1,526
10년 전 조회 1,533
10년 전 조회 1,539
10년 전 조회 1,537
10년 전 조회 1,515
10년 전 조회 2,032
10년 전 조회 1,482
10년 전 조회 1,542
10년 전 조회 1,428
10년 전 조회 2,015
10년 전 조회 1,610
10년 전 조회 1,598
10년 전 조회 1,647
10년 전 조회 1,569
10년 전 조회 1,599