2010-06-03 10 views

답변

0

많은 더 텍스트의 삽입하지 않는 경우http://jsbin.com/uqavo3/2

var nums_of_rows = countLines('textarea_id'); 

    function countLines(areaId){ 
     var theArea = document.getElementById(areaId); 
     var theLines = theArea.value.replace((new RegExp(".{"+theArea.cols+"}","g")),"\n").split("\n"); 
     if(theLines[theLines.length-1]=="") 
     theLines.length--; 
     return theLines.length; 
    }​ 

<textarea cols="#" rows="#" id="">some text here</textarea> 
+0

행의 마지막 줄이 단단한 줄 바꿈이면 중복 계산됩니다. –

2
textBox.value.split("\n").length 
+0

그 선택을 취소하십시오 무엇 여기에 textBox가 있습니까? 텍스트 상자의 ID이거나 ... – picnic4u

+0

아니요, DOM 요소입니다. 'getElementById'로 얻을 수 있습니다. –

+0

이것은 에서만 작동합니다. 텍스트가 자동 줄 바꿈되면 작동하지 않습니다! –

관련 문제