1 <body> 2 <div style="width: 200px; height: 20px;"> 3 <textarea id="inputValue" onkeyup="keyup()"></textarea> 4 </div> 5 </body> 6 <script> 7 //判断回车符,并且获取每一行的内容 8 function keyup(param) { 9 //alert(param); 10 var ss = document.getElementById('inputValue').value; 11 var ary = ss.split('\n'); 12 var list = new Array(); 13 for (var i = 0; i < ary.length; i++) { 14 alert(ary[i]); 15 if (ary[i] != null && ary[i].trim() != "") 16 list.push(ary[i]); 17 } 18 alert(list.length); 19 } 20 </script>