How to count numbers of line in a textarea
问题 I want to make a dynamic textarea, it should increase in rows as the content increase. I am using this code: $("#text_textarea").keyup(function(e) { //splitting textarea value wrt '\n' to count the number of lines if ($(this).val().lastIndexOf('\n')!=-1) var x = $(this).val().split('\n'); $(this).attr( "rows" , x.length+1 ); }); But it fails when user continues to write without giving any new line \n (pressing Enter). 回答1: var keyUpTimeout = false; // Required variables for performance var