how can i get the no. of rows in the multilines textbox thro开发者_如何学运维ugh javascript function if some body inserted many no of text in that textbox
textBox.value.split("\n").length
UPDATED:
DEMO: 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>
精彩评论