setInterval()在Firefox上不起作用 [英] setInterval() not working on firefox

查看:102
本文介绍了setInterval()在Firefox上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java脚本的新手,由于某种原因,当我在 firefox 上运行此代码时, setInterval 似乎不起作用.香港专业教育学院试图在 Microsoft 边缘上运行它,但仍然无法正常工作.它只打印一次日期,但不会从那里继续.任何帮助将不胜感激.

Hi i'm quite new to java script and for some reason setInterval does not seem to work when i run this code on firefox. Ive tried running it on Microsoft edge but it still does not work. It just prints out the date once but does not continue from there. Any help would be appreciated.

谢谢!

 <html>
    <head>
    </head>
    <body>
    <script type = "text/javascript">
    <!--Intervals with Date/time-->
    function printTime(){
        var now = new Date();
        var hours = now.getHours();
        var mins = now.getMinutes();
        var seconds = now.getSeconds();
        document.write(hours+":"+mins+":"+seconds+"<br \>");
    }

    setInterval("printTime()", 1000);//in ms

    </script>
    </body>
    </html>

推荐答案

document.write(是1990年的代码-完全不要使用它... setInterval("printTime(),1000)用不到30年的代码写成 setInterval(printTime,1000)

document.write( is 1990's code - don't use it at all ... also setInterval("printTime()", 1000) in code less than 30 years old is written setInterval(printTime, 1000)

   function printTime(){
        var now = new Date();
        var hours = now.getHours();
        var mins = now.getMinutes();
        var seconds = now.getSeconds();
        document.body.innerHTML += (hours+":"+mins+":"+seconds+"<br \>");
    }

    setInterval(printTime, 1000);//in ms

此处记录

注意:当document.write写入文档流时,在关闭的(已加载)文档上调用document.write将自动调用document.open,这将清除文档.

这篇关于setInterval()在Firefox上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆