这是我的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
function count()
{
var listOfWords, paragraph, listOfWordsArray, paragraphArray;
var wordCounter=0;
listOfWords = document.getElementById("wordsList").value;
//Split the words
listOfWordsArray = listOfWords.split("\n");
//Get the paragrah text
paragraph = document.getElementById("paragraph").value;
paragraphArray = paragraph.split(" ");
//check whether paragraph contains words in list
for(var i=0; i<listOfWordsArray.length; i++)
{
if(paragraph.contains(wordListArray[i]))
{
wordCounter++;
}
}
window.alert("Number of Contains: "+wordCounter);
}
</script>
</head>
<body>
<center>
<p> Enter your Word List here </p>
<br />
<textarea id="wordsList" cols="100" rows="10"></textarea>
<br />
<p>Enter your paragraph here</p>
<textarea id="paragraph" cols="100" rows="15"></textarea>
<br />
<br />
<button id="btn1" onclick="count()">Calculate Percentage</button>
</center>
</body>
</html>
在这里,我要做的是计算paragraph
其中包含多少个单词wordList
。中的单词wordList
用换行符分隔。
但是,我在这里没有得到任何输出。我不太喜欢网络和脚本语言,所以我找不到背后的原因。
我如何计算paragraph
其中还包含多少个单词wordList
?请解释为什么它没有显示?