我知道了,谢谢。我需要将正文移动到 html。更改了正文部分中的一些标签。
}
else
{
window.alert ("You entered an invalid character (" + enterLetter + ") please re-enter");
secondPrompt();
}
}
</script>
<body onload = "firstPrompt();">
<h2>
Word Checker
</h2>
</body>
</html>
最佳答案
您可以在每次找到匹配项时递增 indexOf-
function indexFind(string, charac){
var i= 0, found= [];
while((i= string.indexOf(charac, i))!= -1) found.push(i++);
return found;
}
indexFind('比以往任何时候都更像今天','o');
/* 返回值:(数组) 6,22,48 */
关于javascript - 如何在字符串中查找一个字符并输出该字符出现的每个地方的索引? (JavaScript),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13113147/