Home  >  Article  >  Web Front-end  >  JavaScript implements a simple clock

JavaScript implements a simple clock

高洛峰
高洛峰Original
2016-11-28 09:35:34850browse

[html] 
<html>  
  
<head>  
  
<title>JS实现简单的时钟</title>  
<script>  
  
    function displayTime() {  
        document.getElementById("time").innerHTML = new Date().toTimeString();  
    }   
            
    setInterval(displayTime,1000);      // 每隔1秒钟调用displayTime函数  
</script>  
</head>  
  
<body>  
    <p id="time"></p>  
</body>  
  
</html>

JavaScript implements a simple clock

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn