【发布时间】:2016-03-06 13:33:24
【问题描述】:
在主页上,我有一个最初可以设置的计时器。当时间结束时,会出现一个弹出窗口,其中包含必须完成的测验。我有一个变量 $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 秒。
【问题讨论】:
-
您可能正在为此目的使用 ajax 或 jquery。你在用这样的东西吗?您想向我们展示您的代码吗?
-
@K.Uzair 感谢您的回复!我编辑了问题并向其中添加了一些代码。
标签: javascript php timer popup popupwindow