在主页面上,我有一个我最初可以设置的计时器。当时间结束时,弹出窗口会显示必须完成的测验。我有一个变量$ correctQuestions,用于存储该测验中正确答案的数量。
我想要的是一个PHP函数,用于关闭弹出窗口的按钮并添加重启计时器,如果所有问题都被正确回答,则在初始时间增加30秒,然后删除30。怎么可能这样做?
编辑: 在计时器PHP文件中,我有按钮调用函数来增加/减少js中定时器脚本的时间,以及一个启动定时器的按钮:
<button id="Start-Stop" onclick="clickButton();">START</button>
当时间关闭时,会出现一个弹出窗口,其中包含一组来自数据库的问题
这里是带有按钮调用功能的脚本:
function clickButton()
{
// Code which is not so relevant for my question
document.getElementById("errorLabel").innerHTML = "";
displayTime();
document.getElementById("Start-Stop").innerHTML = "Stop";
start = true;
chosenTime = time;
timer = setInterval(tick, 1000);
// Show the time left
document.getElementById("initialTimeLabel").innerHTML = "Time until exercise:";
} // clickButton
function tick()
{
if(time == 0)
{
clearInterval(timer);
openWindow();
}
else
{
time = time - 1;
}
displayTime();
}
function openWindow()
{
// Choose the selected module and popup an excercise page
var module = document.getElementById("moduleDropdown");
module = module.options[module.selectedIndex].text;
var mylink = "ExercisePage.php?module=" + module;
var windowname = "Questions";
start = false;
time = chosenTime;
displayTime();
document.getElementById("moduleDropdown").disabled = false;
document.getElementById("initialTimeLabel").innerHTML = "Set an initial time:";
document.getElementById("Start-Stop").innerHTML = "Start";
var myWindow = window.open(mylink, windowname, "type=fullwindow,fullscreen=yes,height=screen.availHeight,width=screen.availWidth,left=0,top=0,resizeable=no,scrollbars=yes");
myWindow.focus();
}
当我按下按钮关闭弹出窗口时,如果所有问题都得到正确回答(我有一个变量$ correctQuestions来计算它们),我希望我的计时器以+30秒重新启动,否则为+30秒。
答案 0 :(得分:0)
启动弹出窗口后
var myWindow = window.open("https://www.google.com", "Google", "width=800, height=600");
但是如果你想检查弹出窗口是否已关闭
var interval = window.setInterval(function () {
if (myWindow.closed) {
// Do some stuf here as this will run when the popup has been closed
alert("Child window closed");
window.clearInterval(interval);
}
}, 500);
如果你想点击一些按钮,或者在一段时间后关闭弹出窗口
$myBtn.click(function () {
myWindow.close();
// other code here to reset your timers etc
});