메뉴 건너뛰기

조회 수 7420 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
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();
});

List of Articles
번호 제목 날짜 조회 수
47 유효한 링크인지 확인하는 JAVASCRIPT 2019.01.16 112114
46 금액에 점찍고 한글 표시하기 2019.01.16 1271
45 텍스트박스 입력제한(숫자,영문,한글,특수기호) 2019.01.16 1992
44 span - 동적으로 글자 바꾸기, 보이기 안보이기 2019.01.16 1450
43 풍선도움말 2019.01.16 1167
42 랜덤 배너 노출 스크립트 2019.04.29 11052
41 Alert, Confirm을 모달 팝업으로 만들기 file 2021.03.09 3891
40 Javascript - 이미지 미리보기 회전되어 나옴(EXIF) file 2021.03.09 36368
39 Javascript - 화면 캡처 후 서버에 저장하기(html2canvas 사용법, 주의사항) file 2021.03.09 2176
38 Javascript - 입력한 년, 월의 마지막 날짜 구하기 2021.03.09 224
37 Javascript - Calendar 달력 생성하고 제어하기 2021.03.09 513
36 Javascript - 사업자 등록번호 유효성 체크 file 2021.03.09 1089
35 Javascript - 유효성 체크(이메일 정규식, IP 정규식, 비밀번호 등) 2021.03.09 729
34 javascript - vanillaJS로 체크박스(checkbox) 제어하기 file 2021.03.09 498
33 Javascript - form태그 내부 ajax처리시 2번 전송되는 현상 2021.03.09 268
32 Javascript - Free SVG 한국맵 제어 처리 file 2021.03.09 873
31 Javascript - 입력받은 숫자를 순서대로 홀짝 별로 배열에 삽입하기 2021.03.09 302
30 HTML, Javscript - 선택한 색상으로 배경색 바꾸기(pallet 만들기) file 2021.03.09 717
29 jqgrid 이용한 그리드 활용하기 file 2021.03.25 2341
28 오브젝트 속성 2021.03.25 237
Board Pagination Prev 1 ... 4 5 6 7 8 9 10 11 12 13 Next
/ 13

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved