如何设置输入字段的单词模式

问题描述 投票:0回答:1
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错误消息,而不是警报,但它正在工作,请提供任何帮助,我将不胜感激。

javascript
1个回答
0
投票

document.getElementById("msg").innerHTML="Wrong number of words"

© www.soinside.com 2019 - 2024. All rights reserved.