我在 javascript 中创建了一个倒数计时器函数,并且我正在调用这个函数的正文标记 onload 事件。但我的问题是我想在子页面的标签中显示剩余时间。有没有办法从母版页分配子页中的控件?
这是功能
<script type="text/javascript">
var tim;
var min = 2;
var sec = 0;
function Timer() {
if (min == 0 && sec == 0) {
clearTimeout(tim);
window.location.href = "Result.aspx";
}
else {
if (sec < 1) {
sec = 59;
if (min > 0)
min = min - 1;
}
else
sec = sec - 1;
var mins = "", secs = "";
if (min <= 9)
mins = "0" + min;
else
mins = min;
if (sec <= 9)
secs = "0" + sec;
else
secs = sec;
document.getElementById("lblTimer1").innerHTML = "Time Left : " + mins + " : " + secs;
tim = setTimeout("Timer()", 1000);
}
}
</script>
我在正文 onload 事件中调用 Timer(),而 lblTimer1 是子页面中的标签控件。谢谢, 努桑·高达