JavaScript中的段落 [英] Paragraphs in javascript
本文介绍了JavaScript中的段落的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您是否知道是否有一种简单的方法可以只使用javascript来计数textarea中的段落?
Do you know if there is an easy way of counting paragraphs in a textarea using nothing but javascript?
谢谢
推荐答案
尝试一下:
document.getElementById('textarea_id').value.replace(/\n$/gm, '').split(/\n/).length;
这将忽略空字符串(请参见@Sean Vieira答案)
This will ignore empty strings (see @Sean Vieira answer)
这篇关于JavaScript中的段落的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文