<script type="text/javascript"; language="JavaScript">
<!--
var maxtime = 1 * 60 //一个小时,按秒计算
function CountDown() {
if (maxtime >= 0) {
minutes = Math.floor(maxtime / 60);
seconds = Math.floor(maxtime % 60);
msg = "距离结束时间还有" + minutes + "分" + seconds + "秒";
document.getElementById("timer").innerHTML = msg;
if (maxtime == 0.5 * 60) alert('注意,还有30秒!');
--maxtime;
}
else {
clearInterval(timer);
alert("时间到!考试结束");
document.all.BtnSubmit.click();
}
}
timer = setInterval("CountDown()", 1000);
</script> <div id="timer" style="color:red"> </div>
<script>
function CountDown() {
document.getElementById("timer").innerHTML = "123";
}
</script>
<div id="timer" style="color:red"> </div>
<input type=button onclick="CountDown()" value="test"></input>在我这里可以运行。
function CountDown() {
if (maxtime >= 0) {
minutes = Math.floor(maxtime / 60);
seconds = Math.floor(maxtime % 60);
msg = "距离结束时间还有" + minutes + "分" + seconds + "秒";
document.getElementById("timer").innerHTML = msg;
if (maxtime == 0.5 * 60){
alert('注意,还有30秒!')
};
--maxtime;
}
else {
clearInterval(timer);
alert("时间到!考试结束");
//document.all.BtnSubmit.click();
}
}
timer = setInterval("CountDown()", 1000);
window.onload=function()
{
//这里。
}对象没有加载你就使用了
var maxtime = 6 * 60 //一个小时,按秒计算
function CountDown() {
if (maxtime >= 0) {
minutes = Math.floor(maxtime / 60);
seconds = Math.floor(maxtime % 60);
msg = "距离结束时间还有" + minutes + "分" + seconds + "秒";
document.all["timer"].innerHTML = msg;
if (maxtime == 5 * 60) alert('注意,还有5分钟!');
--maxtime;
}
else {
clearInterval(timer);
alert("时间到!考试结束");
}
}
timer = setInterval("CountDown()", 1000);
}
window.onload=function() {
var maxtime = 6 * 60 //一个小时,按秒计算
function CountDown() {
if (maxtime >= 0) {
minutes = Math.floor(maxtime / 60);
seconds = Math.floor(maxtime % 60);
msg = "距离结束时间还有" + minutes + "分" + seconds + "秒";
document.all["timer"].innerHTML = msg;
if (maxtime == 5 * 60) alert('注意,还有5分钟!');
--maxtime;
}
else {
clearInterval(timer);
alert("时间到!考试结束");
}
}
timer = setInterval("CountDown()", 1000);
}
这样也不对啊
document.getElementById("timer").value= msg;
跟浏览器兼容有关系。