开发者

finding total no of rows in the textbox

开发者 https://www.devze.com 2023-01-01 21:12 出处:网络
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 textboxtextBox.value.split(\"\\n\").length

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

精彩评论

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

关注公众号