我正在寻找创建一个鸡蛋计时器应用程序,用户通过各种表单选择标签传入值。通过这样做,他们设置了计时器,当我尝试这样做时,我得到一个 NaN 错误。在下文中,我有我目前正在使用的 javascript 和一些 HTML,但不是全部。
<html>
<head>
<script language = "javascript" type = "text/javascript">
var minutes
var miuntes=setInterval(timer, 1000); //1000 will run it every 1 second
function timer(m)
{
minutes = m;
minutes=minutes-1;
if (minutes <= 0)
{
clearInterval(minutes);
//counter ended, do something here
return;
}
document.getElementById("txt").innerHTML=minutes + "minutes"; // watch for spelling
}
function checktimer()
{
var checkbox1 = form.preference.value;
var checkbox2 = form.eggsize.value;
var checkbox3 = form.suacepansize.value;
if(checkbox1 == 1 && checkbox2 == 1 && checkbox3 == 1)
{
m = 3;
s = 0;
}
timer(m);
}
</script>
</head>
<body>
<div id = "txt"> </div>
<form id="form" onclick ="checktimer()">
<div class = "question">
<div class="circle"> <h2 class = "whiteh2"> 1 </h2></div>
<div class="question-text"><h6>How do you like your egg? </h6> </div>
<select id="prefernce" name ="preference">
<option value="1">Soft</option>
<option value="2">Medium</option>
<option value="3">Hard</option>
</select>
</div> <!--Ends the question div-->
<div class = "question">
<div class="circle"> <h2 class = "whiteh2"> 2 </h2></div>
<div class="question-text"><h6>What size is your egg? </h6> </div>
<select id="eggsize" name = "eggsize">
<option value="1">Small</option>
<option value="2">Medium</option>
<option value="3">Large</option>
</select>
</div> <!--Ends the question div-->
<div class = "question">
<div class="circle"> <h2 class = "whiteh2"> 3 </h2></div>
<div class="question-text"><h6>What size is the saucepan? </h6> </div>
<select id="saucepansize" name = "suacepansize">
<option value="1">Small</option>
<option value="2">Medium</option>
<option value="3">Large</option>
</select>
</div> <!--Ends the question div-->
<div class = "question">
<input type="submit" id="button" name="submit" value = "Go" onclick="checktimer()"/> <br/>
</div>
</form>
</div> <!--Ends the main form div-->
</body>
</html>