checkCount 함수 (indexOf 로 갯수 세기)
<textarea rows=”6″ style=”width: 99%; overflow: hidden;” id=”req_content” onkeyup=”expandArea()” name=”req_content”><c:out
<script type=”text/javascript”>
function expandArea(){
var returnCount = checkCount(“#req_content”, “\n”);
if (returnCount < 6) {
$(“#req_content”).attr(“rows”, “6”);
} else {
$(“#req_content”).attr(“rows”, returnCount + 1);
}
}
function checkCount(_selector, _findChar) {
var val = $(_selector).val();
if (val == null || val.length == 0) {
return 0;
}
var totalCount = 0;
var axisPos = -2;
var loopCnt = 0;
while (true) {
axisPos = val.indexOf(_findChar, axisPos + 1);
if (axisPos < 0) {
break;
}
totalCount ++;
loopCnt++;
if (loopCnt > 1000) {
break;
}
}
return totalCount;
}