<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>

解决方案 »

  1.   

    新建一个html文档,复制如下代码:
    <script>
    function CountDown() {
    document.getElementById("timer").innerHTML = "123";
    }
    </script>
    <div id="timer" style="color:red"> </div>
    <input type=button onclick="CountDown()" value="test"></input>在我这里可以运行。
      

  2.   

    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);
      

  3.   

    不你代码放在
    window.onload=function()
    {
     //这里。
    }对象没有加载你就使用了
      

  4.   

    html解析先后顺序问题。script放到最后执行。或者写个执行方法。在onload执行。如#6楼一样。
      

  5.   

    六楼是说这样吗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);
                }
      

  6.   


    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);
                }
    这样也不对啊
      

  7.   

    帅哥,用label控件不可以吗?
    document.getElementById("timer").value= msg;
      

  8.   

    document.getElementById("timer").innerHTML = msg;取timer没取到,把脚本放到页脚。你放到上面,页面还没rander完,脚本抓dom元素肯定抓不到。
      

  9.   

    按你的代码我再IE9和Chrome下测试时没有问题的,
    跟浏览器兼容有关系。