function wordCount(text) {
totalCount = 0;
words = text.split(' ')
words.forEach(function(word) {
if (word.length > 0) {
totalCount++;
}
})
return totalCount;
}
window.myFunction = function() {
textarea = document.getElementById('txt');
words = wordCount(textarea.value);
if(words < 7 || words > 12) {
alert('Wrong number of words');
}
}
我在这里得到了这段代码,它工作得很好,但我希望它显示innerhtml错误消息,而不是警报,但它正在工作,请提供任何帮助,我将不胜感激。
document.getElementById("msg").innerHTML="Wrong number of words"