I'm trying to write a function that return the value of non-whitespace characters that are inside a textarea. I'm supposed to use replace and the regex given to me to separate whitespace and actual characters but I just don't understand how I'm supposed to get the count. Could someone explain it to me please?
function countText()
{
var commentText;
var commentBox = document.getElementById('comment'); //comment is my textArea ID
var commentregx = "/\s/g"; // whitespace regex
commentText = commentBox.value.replace(commentregx, ""); // commentText is supposed to hold the number of non-whitespace values.
}
If needed I can throw this into a jsfiddle with my other functions.
replace
返回没有空格的字符串,所以只需抓住它的长度:
commentText = commentBox.value.replace(commentregx, "").length;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.