我正在设置一个计时器,但我做错了。所以请任何人给我更好的方法来做到这一点。
这是我写的代码....我知道我做错了,但它的工作原理。我设置了 40 秒的计时器。
<!DOCTYPE html>
<html><head><title>Online</title>
<script language="javascript">
function timedText()
{
var x=document.getElementById('txt');
var t40=setTimeout(function(){x.value="40 sec "},1000);
var t39=setTimeout(function(){x.value="39 sec "},2000);
var t38=setTimeout(function(){x.value="38 sec "},3000);
var t37=setTimeout(function(){x.value="37 sec "},4000);
var t36=setTimeout(function(){x.value="36 sec "},5000);
var t35=setTimeout(function(){x.value="35 sec "},6000);
var t34=setTimeout(function(){x.value="34 sec "},7000);
var t33=setTimeout(function(){x.value="33 sec "},8000);
var t32=setTimeout(function(){x.value="32 sec "},9000);
var t31=setTimeout(function(){x.value="31 sec "},10000);
var t30=setTimeout(function(){x.value="30 sec "},11000);
var t29=setTimeout(function(){x.value="29 sec "},12000);
var t28=setTimeout(function(){x.value="28 sec "},13000);
var t27=setTimeout(function(){x.value="27 sec "},14000);
var t26=setTimeout(function(){x.value="26 sec "},15000);
var t25=setTimeout(function(){x.value="25 sec "},16000);
var t24=setTimeout(function(){x.value="24 sec "},17000);
var t23=setTimeout(function(){x.value="23 sec "},18000);
var t22=setTimeout(function(){x.value="22 sec "},19000);
var t21=setTimeout(function(){x.value="21 sec "},20000);
var t20=setTimeout(function(){x.value="20 sec "},21000);
var t19=setTimeout(function(){x.value="19 sec "},22000);
var t18=setTimeout(function(){x.value="18 sec "},23000);
var t17=setTimeout(function(){x.value="17 sec "},24000);
var t16=setTimeout(function(){x.value="16 sec "},25000);
var t15=setTimeout(function(){x.value="15 sec "},26000);
var t14=setTimeout(function(){x.value="14 sec "},27000);
var t13=setTimeout(function(){x.value="13 sec "},28000);
var t12=setTimeout(function(){x.value="12 sec "},29000);
var t11=setTimeout(function(){x.value="11 sec "},30000);
var t10=setTimeout(function(){x.value="10 sec "},31000);
var t9=setTimeout(function(){x.value="9 sec "},32000);
var t8=setTimeout(function(){x.value="8 sec "},33000);
var t7=setTimeout(function(){x.value="7 sec "},34000);
var t6=setTimeout(function(){x.value="6 sec "},35000);
var t5=setTimeout(function(){x.value="5 sec "},36000);
var t4=setTimeout(function(){x.value="4 sec "},37000);
var t3=setTimeout(function(){x.value="3 sec "},38000);
var t2=setTimeout(function(){x.value="2 sec "},39000);
var t01=setTimeout(function(){x.value="1 sec "},40000);
var t0=setTimeout(function(){x.value="0 sec "},41000);
var wc=setTimeout(function()
{
document.quest.submit();
window.open('best2.php?username=$username');
window.close('best1.php?username=$username');
},42000);
}
</script>
</head>
<body onload="timedText()">
<br><br>
<form name="quest" method="POST" action="">
<p align='right'><b>Time left to answer this Question : </b>
<input type="text" id="txt" /></p>
<p><b>Question 1 : </b> Vanessa and Brett had been arguing about their perceived
proclivity to spend for hours together. What word describes the couple's predicament? <br></p>
<p><input type="radio" value="Wrong" name="ans" id="r1">Demarche </p>
<p><input type="radio" value="Correct" name="ans" id="r2">Impasse </p>
<p><input type="radio" value="Wrong" name="ans" id="r3">Mélange </p>
<p><input type="radio" value="Wrong" name="ans" id="r4">tête-à-tête </p>
<input type="submit" name="NEXT" value="Next" >
<br/>
<br/>
</form>
</body>
</html>