var EnglishDictionary = ["Pants", "Pencil Sharpener", "Lampshade", "Pillow", "Hat", "Speaker", "Blueberry", "Strawberry", "Banana", "Starfruit", "Apple", "Mango", "Peach", "Where am I?", "How are you?", "Hello, Whats your name?", "Where is the bathrooom?", "How do I get Home?", "Where is the Resturaunt?"];
var DutchDictionary = ["overhemd", "broek", "puntenslijper", "lampschaduw", "hoofdkussen", "hoed", "spreker", "Bosbes", "Aardbei", "banaan", "stervrucht", "appel", "Mango", "Perzik", "waar ben ik?", "hoe gaat het met je?", "Hallo hoe heet je?", "Waar is de badkamer?", "Hoe kom ik thuis?", "Waar is het toilet?"];
var wordImages = ["Pants.jpg", "Pencil Sharpener.jpg", "Lampshade.jpg", "Pillow.jpg", "Hat.jpg", "Speaker.jpg", "Blueberry.jpg", "Strawberry.jpg", "Banana.jpg", "Starfruit.jpg", "Apple.jpg", "Mango.jpg", "Peach.jpg", "Where am I.jpg", "How are you.jpg", "Hello, What is your name.jpg", "Where is the Bathroom.jpg", "How do I get home.jpg", "Where is the Resturaunt.jpg"];
var wordIndex;
var translatedWord;
var selectedImage;
var displayImage;
var findWord;
var findImage;
function translateWord(word) {
translatedWord = findWord(word);
selectedImage = findImage(word);
document.getElementById("output").value += " " + translatedWord;
displayImage = document.getElementById("displayImages").checked;
if (displayImage == true) {
document.getElementById("image").src = selectedImage;
}
}
function findWord(word) {
for (wordIndex in EnglishDictionary) {
if (word == EnglishDictionary[wordIndex]) {
return DutchDictionary[wordIndex];
}
}
}
function findImage(word) {
for (wordIndex in EnglishDictionary) {
if (word == EnglishDictionary[wordIndex]) {
return wordImages[wordIndex];
}
}
}
<button onclick="translateWord('Pillow')" class="button">Pillow</button>
<input type="text" id="output">
<input type="checkbox" id="displayImages">
<img id="image" src="" />
这是我的按钮组的javascript,但是当我按下按钮时没有任何作用,我一直在
未捕获的ReferenceError:未定义translateWord
这是什么意思,我该如何解决它。谢谢。这是一个学校项目。
答案 0 :(得分:1)
你的脚本标签有拼写错误&#34; javasript&#34;。它应该是javascript
<script type="text/javascript">
var EnglishDictionary = ["Pants","Pencil Sharpener","Lampshade","Pillow","Hat","Speaker","Blueberry","Strawberry","Banana","Starfruit","Apple","Mango","Peach","Where am I?","How are you?","Hello, Whats your name?","Where is the bathrooom?","How do I get Home?","Where is the Resturaunt?"];
var DutchDictionary = ["overhemd","broek","puntenslijper","lampschaduw","hoofdkussen","hoed","spreker","Bosbes","Aardbei","banaan","stervrucht","appel","Mango","Perzik","waar ben ik?","hoe gaat het met je?","Hallo hoe heet je?","Waar is de badkamer?","Hoe kom ik thuis?","Waar is het toilet?"];
var wordImages = ["Pants.jpg","Pencil Sharpener.jpg","Lampshade.jpg","Pillow.jpg","Hat.jpg","Speaker.jpg","Blueberry.jpg","Strawberry.jpg","Banana.jpg","Starfruit.jpg","Apple.jpg","Mango.jpg","Peach.jpg","Where am I.jpg","How are you.jpg","Hello, What is your name.jpg","Where is the Bathroom.jpg","How do I get home.jpg","Where is the Resturaunt.jpg"];
var wordIndex;
var translatedWord;
var selectedImage;
var displayImage;
var findWord;
var findImage;
function translateWord(word)
{ alert(2)
translatedWord = findWord(word);
selectedImage = findImage(word);
document.getElementById("output").value += " " + translatedWord;
displayImage = document.getElementById("displayImages").checked;
if (displayImage == true)
{
document.getElementById("image").src = selectedImage;
}
}
function findWord(word)
{
for (wordIndex in EnglishDictionary)
{
if (word == EnglishDictionary[wordIndex])
{
return DutchDictionary[wordIndex];
}
}
}
function findImage(word)
{
for (wordIndex in EnglishDictionary)
{
if (word == EnglishDictionary[wordIndex])
{
return wordImages[wordIndex];
}
}
}
</script>
<button onclick= "translateWord('Pillow')" class="button">Pillow</button>