今天在百度经验发现一句代码,极其简单的js获取时间直接显示。
首先新建一个容器
譬如一个<Span></Span>
然后上js:
<script>
function showTime(){
var curTime = new Date();
$("#jstime").html(curTime.toLocaleTimeString());
setTimeout("showTime()",1000)
}
$(function (){showTime()})
</script>
jsTime就是我们的容器,如下图:
效果图如下:
下课!