[英]javascript: I want to count words in my textarea it doesn't count words after I press enter key
please help me change this countword function to continue counting after i press enter key请帮我更改此计数功能以在我按下 Enter 键后继续计数
function countWords(text) {
var normalizedText = text.
replace(/(\r\n|\n|\r)/gm, " ").
replace(/^\s+|\s+$/g, "").
replace(" ", " ");
normalizedText = strip(normalizedText);
var words = normalizedText.split(/\s+/);
for (var wordIndex = words.length - 1; wordIndex >= 0; wordIndex--) {
if (words[wordIndex].match(/^([\s\t\r\n]*)$/)) {
words.splice(wordIndex, 1);
}
}
return (words.length);
}
If the page submits, wrap the fields in <form></form>
如果页面提交,将字段包裹在
<form></form>
and have并且有
document.querySelector("form").onsubmit=function() { return false }
in a script after it在它之后的脚本中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.