천

textarea 글자수 카운트 입니다.

· 2016-01-05 (화) 11:12:21 · 2767 · 1

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개

감사합니다.
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

8,188건
+
제목 글쓴이 날짜 조회
16-01-11 조회 2,578
16-01-11 조회 2,395
16-01-11 조회 2,613
16-01-08 조회 2,802
16-01-08 조회 2,559
16-01-07 조회 2,579
16-01-05 조회 2,595
16-01-05 조회 2,607
16-01-05 조회 2,909
16-01-05 조회 2,725
16-01-05 조회 2,768
16-01-04 조회 2,621
16-01-04 조회 2,629
16-01-04 조회 2,584
16-01-04 조회 2,495
16-01-03 조회 3,325
16-01-03 조회 2,640
16-01-03 조회 2,909
16-01-02 조회 2,835
16-01-02 조회 2,578
16-01-02 조회 2,694
16-01-02 조회 2,473
16-01-01 조회 2,769
16-01-01 조회 2,694
16-01-01 조회 2,774
15-12-31 조회 2,555
15-12-31 조회 3,260
15-12-31 조회 2,854
15-12-31 조회 2,880
15-12-31 조회 2,689
15-12-30 조회 2,637
15-12-30 조회 3,200
15-12-30 조회 2,837
15-12-30 조회 2,727
15-12-30 조회 2,641
15-12-30 조회 2,558
15-12-29 조회 2,584
15-12-29 조회 2,779
15-12-29 조회 2,878
15-12-29 조회 2,598
15-12-28 조회 2,615
15-12-28 조회 2,641
15-12-28 조회 2,670
15-12-28 조회 2,507
15-12-27 조회 3,181
15-12-27 조회 2,645
15-12-27 조회 2,546
15-12-27 조회 2,603
15-12-26 조회 2,564
15-12-26 조회 2,632
15-12-26 조회 2,654
15-12-25 조회 3,340
15-12-25 조회 2,532
15-12-25 조회 2,533
15-12-25 조회 2,490
15-12-24 조회 3,027
15-12-24 조회 2,650
15-12-24 조회 2,656
15-12-24 조회 2,679
15-12-24 조회 2,633
15-12-23 조회 2,801
15-12-23 조회 2,620
15-12-23 조회 2,490
15-12-23 조회 2,619
15-12-23 조회 2,568
15-12-22 조회 2,748
15-12-22 조회 2,610
15-12-22 조회 2,590
15-12-22 조회 2,498
15-12-21 조회 2,533
15-12-21 조회 2,569
15-12-21 조회 2,534
15-12-20 조회 2,581
15-12-20 조회 2,747
15-12-20 조회 2,526
15-12-19 조회 2,603
15-12-19 조회 2,592
15-12-19 조회 2,602
15-12-18 조회 2,905
15-12-18 조회 2,577
15-12-18 조회 2,562
15-12-18 조회 2,540
15-12-17 조회 2,611
15-12-17 조회 2,533
15-12-17 조회 2,536
15-12-17 조회 2,503
15-12-16 조회 2,518
15-12-16 조회 2,554
15-12-16 조회 2,495
15-12-16 조회 2,707
15-12-15 조회 2,846
15-12-15 조회 2,777
15-12-15 조회 2,508
15-12-15 조회 2,506
15-12-15 조회 2,498
15-12-14 조회 2,571
15-12-14 조회 2,655
15-12-14 조회 2,478
15-12-13 조회 2,447
15-12-13 조회 2,488