我想为我的在线考试网站创建一个计时器控件
<script src="~/Scripts/jquery.js"></script>
<script src="~/Scripts/jquery-1.5.1.js"></script>
<script type="text/javascript">
var myVar = setInterval(function () { myTimer() }, 1000);
var d = new Date();
d.setHours(00, 5, 59, 00);
function myTimer() {
if (d.getSeconds() <= 1)
d.setMinutes(d.getMinutes() - 1, 59, 00);
var h = d.getHours();
var m = d.getMinutes();
var s = d.getSeconds() - 1;
if (m == 0 && s == 1)
window.location.href = "showresults.aspx";
document.getElementById(" lblCtime.ClientID ").innerHTML = h + ":" + m + ":" + s;
d.setMinutes(m, s);
//setInterval(myTimer, 1000);
}
</script>
<div style="height:250px;width:400px">
time left :<Label ID="lblCtime" Font-Bold="True" Font-Names="Verdana"
ForeColor="Red"></Label>
我想为我的在线检查网站创建一个计时器控件,代码如上所示我为此写了javascript和我的scrips执行但跳过mytimer函数尝试了下面提到的代码
答案 0 :(得分:2)
此处您有错误错误ID 已通过:
document.getElementById(" lblCtime.ClientID ").innerHTML = h + ":" + m + ":" + s;
^ ^
给出错误:
Uncaught TypeError: Cannot set property 'innerHTML' of null
试试这段代码:
document.getElementById("lblCtime").innerHTML = h + ":" + m + ":" + s;
<强> DEMO 强>
答案 1 :(得分:0)
替换:
var myVar = setInterval(function () { myTimer() }, 1000);
使用:
var myVar = setInterval(myTimer, 1000);
您只需要传递对setInterval