$(document).ready(function() {

document.oncontextmenu = new Function('return false');

document.ondragstart = new Function('return false');

document.onselectstart = new Function('return false');


$(function() {function updateInputCount() {

$("[id^=careerDesc_]").each(function(i){


var totalByte = 0;    // 총 byte 수

var savaMsg = "";    // 최대 byte수 초과시 textarea에 담아줄 값

var message = $(this).val();    // 현재 입력된 값


// 현재 입력된 값의 글자수 만큼 for문을 돌린다.

for(var i =0; i < message.length; i++) {

// 해당 글자의 code를 가져온다

var currentByte = message.charCodeAt(i);


// 한글은 2자, 그외는 1자를 추가해준다

if(currentByte > 128) totalByte += 2;

else totalByte++;


// 최대 Byte가 되기 전까지 메시지를 저장한다.

if(totalByte <= 400){

savaMsg += message.charAt(i);

}

}


var cnt = totalByte;

$(this).next().children().first().text(cnt);


if(cnt >= 400){

// 최대 Byte 수를 넘은 경우 textarea에 저장한 msg를 담아준다.

$(this).val(savaMsg);

}

});

}


$('textarea')

.focus(updateInputCount)

.blur(updateInputCount)

.keypress(updateInputCount);

window.setInterval(updateInputCount, 100);

updateInputCount();

});

});





[BODY]

<p class="txt_long byte"><span class="inputCnt">0</span>/400byte</p>

span class에 inputCnt를 넣어주면 자동으로 현재 byte수를 담아준다.


+ Recent posts