Javascript switch语句有时才起作用
开关一开始不起作用,但单击几下后,案例7确实出现了。我使用了一个警报来确保speechNum++工作正常,它确实工作了。我还使用了带有===的if语句来确保speechNum仍然是一个数字,它也做到了这一点。这是在我添加了save和cheat函数之后开始的(尽管我不知道怎么做)。只有Javascript可能有问题。我有一个理论,我把a}放错地方了,但是,如果是的话,我找不到它。我知道图像不会出现,但这没关系。提前谢谢Javascript switch语句有时才起作用,javascript,switch-statement,Javascript,Switch Statement,开关一开始不起作用,但单击几下后,案例7确实出现了。我使用了一个警报来确保speechNum++工作正常,它确实工作了。我还使用了带有===的if语句来确保speechNum仍然是一个数字,它也做到了这一点。这是在我添加了save和cheat函数之后开始的(尽管我不知道怎么做)。只有Javascript可能有问题。我有一个理论,我把a}放错地方了,但是,如果是的话,我找不到它。我知道图像不会出现,但这没关系。提前谢谢 var gameContainer=document.getElementB
var gameContainer=document.getElementById(“游戏容器”);
变量性别;
var name=“”;
var speechBox=document.createElement(“DIV”);
speechBox.id=“语音盒”;
var speechP=document.createElement(“P”);
speechP.id=“speech-p”
var speech=document.createTextNode(“”);
var-speechNum=0;
var text=true;
功能主菜单(){
gameContainer.removeChild(document.getElementById(“开始按钮”);//按钮消失
document.body.removeChild(document.getElementById('warning');//警告消失
var mainMenuBox=document.createElement(“DIV”);
mainMenuBox.id=“主菜单框”;
var mainMenuBoxNew=document.createElement(“P”);
mainMenuBoxNew.className=“main-menu-box-p”;
mainMenuBoxNew.innerHTML=“新游戏”;
var mainMenuBoxNewPic=document.createElement(“IMG”);
mainMenuBoxNewPic.className=“主菜单框pic”;
mainMenuBoxNewPic.src=“index/src/img/menu/red.gif”
mainMenuBoxNew.appendChild(mainMenuBoxNewPic);
mainMenuBoxNew.onmouseinter=function(){mainMenuBoxNewPic.src=“index/src/img/menu/redAnimated.gif”;}
mainMenuBoxNew.onmouseleave=function(){mainMenuBoxNewPic.src=“index/src/img/menu/red.gif”;}
mainMenuBoxNew.onclick=function(){gameContainer.removeChild(mainMenuBox);
预处理开放();
返回;
}
var mainMenuBoxSave=document.createElement(“P”);
mainMenuBoxSave.className=“main-menu-box-p”;
mainMenuBoxSave.innerHTML=“保存代码”;
var mainMenuBoxSavePic=document.createElement(“IMG”);
mainMenuBoxSavePic.className=“主菜单框pic”;
mainMenuBoxSavePic.src=“index/src/img/menu/binary.jpg”;
mainMenuBoxSave.appendChild(mainMenuBoxSavePic);
mainMenuBoxSave.onMouseCenter=function(){mainMenuBoxSavePic.src=“index/src/img/menu/binaryAnimated.gif”;}
mainMenuBoxSave.onmouseleave=function(){mainMenuBoxSavePic.src=“index/src/img/menu/binary.jpg”;}
mainMenuBoxSave.onclick=function(){gameContainer.removeChild(mainMenuBox);
inputSaveCode();
返回;
}
var mainMenuBoxCheat=document.createElement(“P”);
mainMenuBoxCheat.className=“main-menu-box-p”;
mainMenuBoxCheat.innerHTML=“作弊代码”;
var mainMenuBoxCheatPic=document.createElement(“IMG”);
mainMenuBoxCheatPic.className=“主菜单框pic”;
mainMenuBoxCheatPic.src=“index/src/img/menu/cheatCode.jpg”;
appendChild(mainMenuBoxCheatPic);
mainMenuBoxCheat.onMouseCenter=function(){mainMenuBoxCheatPic.src=“index/src/img/menu/cheatCodeAnimated.gif”}
mainMenuBoxCheat.onmouseleave=function(){mainMenuBoxCheatPic.src=“index/src/img/menu/cheatCode.jpg”;}
mainMenuBoxCheat.onclick=function(){gameContainer.removeChild(mainMenuBox);
inputCheatCode();
返回;
}
gameContainer.appendChild(mainMenuBox);
mainMenuBox.appendChild(mainMenuBoxNew);
mainMenuBox.appendChild(mainMenuBoxSave);
appendChild(mainMenuBoxCheat);
}
函数prepofessoropen(){
document.body.style.backgroundImage=“url(index/src/img/yellowdmond/professor.png)”;
gameContainer.appendChild(speechBox);
speechBox.appendChild(speechP);
speechP.innerHTML=“欢迎来到Poké;mon,clod!”的世界;
speechBox.onclick=function(){professorOpen();}
函数教授开放式(){
speechNum++;
开关(特殊技术){
案例1:
speech=“我是黄钻,现在只能介绍Poké;mon衍生产品了。”;
打破
案例2:
speech=“这个土块世界广泛居住着被称为Poké;mon的生物。”;
打破
案例3:
speech=“这些神秘的生物可以在世界的每个角落找到……”;
打破
案例4:
speech=“有些人跑过平原,有些人飞过天空,还有一些人在海洋深处游泳……”;
打破
案例5:
speech=“土块和这些土拨鼠生活在一起,相互提供一点力量来生存和繁荣。”;
打破
案例6:
speech=“让我们从一些快速的问题开始…
你是男孩还是女孩?
(如果Alex与你分享了这个,可能是男孩)。”;
打破
案例7:
speechBox.onclick=function(){}
speechBox.style.cursor='default';
speechBox.innerHTML='男孩\
女孩
document.getElementById(“男性”).onclick=function(){gender=“boy”;professorOpen();return;}
document.getElementById(“女性”).onclick=function(){gender=“girl”;professorOpen();return;}
打破
案例8:
speechBox.innerHTML=“
那么,你是“+gender+”?
\
是的\
\
显然不是。”;
document.getElementById(“yes-gender-p”).onclick=function(){professorOpen();return;}
document.getElementById(“no-gender-p”).onclick=function(){speechNum=6;professorOpen();return;}
打破
案例9:
speechBox.onclick=function(){professorOpen();}
speechBox.innerHTML=“”;
speechBox.appendChild(speechP);
speechBox.style.cursor='pointer';
speech=“还有,你是什么
switch (speechNum) {
case 1:
speechP.innerHTML = "I am Yellow Diamond – reduced to introducing Pokémon Spin-Offs.";
break;
case 2:
speechP.innerHTML = "This world of clods is widely inhabited by creatures known as Pokémon.";
break;