我想计算文本区域的字数、字符数和行数。这是我的代码:这样做是否完美?
function getStats() {
var text = textarea.value,
chars = text.length,
words = text.split(/\S+/g).length - 1,
lines = text.split("\n").length;
return lines + " lines, " + words + " words, " + chars + " chars";
}
有什么更正吗?