【发布时间】:2018-07-28 00:00:10
【问题描述】:
我正在尝试创建一个使用文本字段从用户那里获取输入的应用程序。将字符串拆分为空格并在字符串中查找坏词。如果找到坏词,则在 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
}
【问题讨论】:
-
可能只是一个错字,但您实际上并没有在提供的 html 中调用该函数。
标签: javascript arrays loops dom output