当前位置:编程学习 > JAVA >>

Javascript版时钟

共享一段 Javascript 版时钟代码:


[javascript]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Javascript版时钟</title> 
<script> 
var oInterval=""; 
function fnRecycle(){ 
    var oDate=new Date(); 
    var sSwitch="AM";//上午 
    var iHours=oDate.getHours(); 
    if(iHours>12){ 
        iHours-=12; 
        sSwitch="PM";//下午 
    } 
    var sMinutes=oDate.getMinutes() + ""; 
    if(sMinutes.length==1){ 
        sMinutes="0" + sMinutes; 
    } 
    var sSeconds=oDate.getSeconds() + ""; 
    if(sSeconds.length==1){ 
        sSeconds="0" + sSeconds; 
    } 
    oTimer.innerHTML=iHours + ":" + sMinutes + ":" + sSeconds + " " + sSwitch; 

function window_onload() { 
if(oInterval==""){ 
        oInterval=window.setInterval("fnRecycle()",1000); 
    } 

</script> 
</head> 
 
<body  language="javascript" onload="return window_onload()"> 
 
<!-- 页面调用 --> 
Javascript版时钟:<span id="oTimer" ></span> 
 
</body> 
</html> 


Over!!!

 

摘自 SongYanJun2011
补充:web前端 , JavaScript ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,