我正在尝试创建一个应用程序,使用文本字段从用户那里获取输入。将字符串按空格分割并查找字符串中的不良词汇。如果找到不良词汇,则在DOM上输出结果。
我一直在寻找表单,但是没有找到。我找到了一些PHP表单,但这对我没有帮助。我相信我有正确的伪代码。需要一些指导。
以下是HTML:
<body>
<input type="text" id="wordInput"/>
<button id="badWordCatch" onclick="badWordCatch;">Catch Bad Words</button>
<div id="wordsFound"></div>
<div id="wordAmount"></div>
</body>
Javascript如下:
1. What words are put it
2. if the words are bad or not
*/
function badWordCatch(){
var wordInput = document.getElementById("wordInput").value;
// split the words by spaces (" ")
var arr = wordInput.split(" ");
// bad words to look for
var badWords = ["legos", "cloud", "manifold"];
//find bad words from the input
//output on the dom "if bad words were found"
//output on the dom how many bad words were found
}