开发者

finding total no of rows in the textbox

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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜