0
我在我的HTML中有一个图像,但我想在用户给出答案时更改图像。出于某种原因,第一个功能的作品,但图像不会改变..有人可以帮助我。更改switch语句中的图像
这是我到目前为止的代码:
window.onload = function() {
'use strict';
var showMessage = function (text) {
var messageCenter = document.getElementById('messageCenter');
messageCenter.innerHTML += "<p>" + text + "</p>\n";
};
var checkName = function (name) {
switch (prompt("What is your name?")) {
case "Leonard":
showMessage("Leonard! How did I not recognize you! Why would you like to get rid of me!");
break;
case "Penny":
showMessage("Penny Penny Penny! You've got so much to learn.");
break;
case "Howard":
showMessage("Howard, the only one without a Ph.D");
break;
case "Raj":
showMessage("Interesting. You're afraid of insects and women. Ladybugs must render you catatonic!");
break;
default:
showMessage("Well, I'm not familiair with you. I don't like to talk to strange people.");
break;
}
};
checkName()
var myImage = document.getElementById('sheldon');
var checkCase = function (img) {
switch (img) {
case "Leonard":
myImage("verbaasd.jpg");
break;
case "Penny":
myImage("les.jpg");
break;
case "Howard":
myImage("howard.jpg");
break;
case "Raj":
myImage("loser.jpg");
break;
default:
myImage("sheldon.jpg");
break;
}
};
checkCase()
};
您可以在'switch'块或'showMessage'函数或其他函数中执行此操作。你有没有尝试过?这种尝试以什么方式不起作用? – David 2013-04-03 19:30:05
为什么你不试试,让我们知道它是如何工作的! – jahroy 2013-04-03 19:30:09
老师说我不得不使用另一个函数,但是我不知道如何开始:( – Mononootje 2013-04-03 19:33:16