我正在创建一个在线游戏,玩家必须在关闭弹出窗口时回答问题。如果他们回答错误,他们会收到警告,告诉他们他们是否不正确。如果他们回答正确,他们会收到下一个问题的弹出窗口。我的功能不正确,但如果正确的位工作,我无法弹出。我究竟做错了什么?请注意,我对 Javascript 很陌生,所以这几乎完全是其他人的代码。
function Start1(URL1, WIDTH, HEIGHT) {
windowprops = "left=50,top=50,width=" + WIDTH + ",height=" + HEIGHT;
preview = window.open(URL1, "", windowprops);
}
function doPopup1() {
url1 = "focus.html";
width = 500; // width of window in pixels
height = 500; // height of window in pixels
delay = 5; // time in seconds before popup opens
timer = setInterval("Start1(url1, width, height)", delay*1000);
}
function doPopup2() {
url2 = "q1.html";
width = 500; // width of window in pixels
height = 500; // height of window in pixels
delay = 1; // time in seconds before popup opens
timer = setTimeout("Start1(url2, width, height)", delay*1000);
}
function checkAnswer (form){
var Answer = form.Answer.value;
if (Answer == "2"){
doPopup2();
}
else{
alert ("Incorrect")
}
}
<body OnLoad="doPopup1();">
然后是一个基本的 HTML 表格,但重要的部分是:
<input type="submit" name="Submit" value="Submit" onClick="checkAnswer(this.form)" />