메뉴 건너뛰기

조회 수 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
번호 제목 날짜 조회 수
247 바닐라 JS, ECMAScript 개념 file 2023.01.20 109
246 마우스 오른쪽버튼 , 드래그 선택 차단 2023.01.12 118
245 패스워드, 확인패스워드가 맞는지 체크 2023.01.12 129
244 Node.js와 npm(+ npx)의 개념 2023.01.20 134
243 비동기 작업의 원리 (JavaScript 엔진, Web API, Task Queue, Event Loop) file 2023.01.20 138
242 개발자도구 F12키 막기 file 2023.01.12 169
241 페이지 이동 2021.03.26 190
240 getYear(); 크롬, 파이어폭스 에서 제대로 작동 안하는 문제 2021.03.26 197
239 default 매개변수(매개변수 기본값) 2021.03.26 199
238 자주쓰는 것들 2021.03.26 203
237 split, join, replace, replace_all 2021.03.26 204
236 폼안에 태그명, 함수명 같을때 오류 2021.03.26 214
235 현재 날짜, 시간 ( Month + 1 에 대해서 ) 2021.03.25 218
234 Date 객체로 원하는 날짜, 시간 표현하기 2021.08.20 223
233 Javascript - 입력한 년, 월의 마지막 날짜 구하기 2021.03.09 224
232 3자리 마다 쉼표만 찍어주는 number_format 함수 2021.03.26 225
231 오브젝트 속성 2021.03.25 237
230 월의 마지막 날짜 계산하기 2021.08.20 242
229 대소문자 변경 (대문자를 소문자로, 소문자를 대문자로) 2021.08.20 261
228 Javascript - form태그 내부 ajax처리시 2번 전송되는 현상 2021.03.09 268
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 13 Next
/ 13

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved