js捕获回车事件,并且获取每一条输入内容

时间:2022-05-20 19:57:42
 <body>
<div style="width: 200px; height: 20px;">
<textarea id="inputValue" onkeyup="keyup()"></textarea>
</div>
</body>
<script>
//判断回车符,并且获取每一行的内容
function keyup(param) {
//alert(param);
var ss = document.getElementById('inputValue').value;
var ary = ss.split('\n');
var list = new Array();
for (var i = 0; i < ary.length; i++) {
alert(ary[i]);
if (ary[i] != null && ary[i].trim() != "")
list.push(ary[i]);
}
alert(list.length);
}
</script>