首页 > 代码库 > 48.判断文本中回车的数量

48.判断文本中回车的数量


技术分享
 1 <!DOCTYPE html>
 2 <html>
 3 <head lang="en">
 4     <meta charset="UTF-8">
 5     <title>判断文本中回车的数量</title>
 6 </head>
 7 <body>
 8 <textarea id="t" cols="30" rows="10">
 9 </textarea>
10 <button id="btn" onclick="tom()">获取</button>
11 <script>
12 
13     var tom = function () {
14         c = document.getElementById(‘t‘).value;
15         var counts = c.split(‘\n‘).length - 1;
16         alert(‘总共有‘ + counts + "个回车");
17     }
18 </script>
19 
20 </body>
21 </html>
View Code

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>判断文本中回车的数量</title>
</head>
<body>
<textarea id="t" cols="30" rows="10">
</textarea>
<button id="btn" onclick="tom()">获取</button>
<script>

var tom = function () {
c = document.getElementById(‘t‘).value;
var counts = c.split(‘\n‘).length - 1;
alert(‘总共有‘ + counts + "个回车");
}
</script>

</body>
</html>

48.判断文本中回车的数量