以下是 js可爱糖果样式数字时间代码 的示例演示效果:
部分效果截图:
HTML代码(index.html):
<!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>js可爱糖果样式数字时间代码</title>
</head>
<body>
<script>
window.onload=function(){
getTime();
}
function getTime(){
var date = new Date();
var hours =formatTime(date.getHours());
var minutes = formatTime(date.getMinutes());
var seconds = formatTime(date.getSeconds());
var $time = document.getElementById('time');
$time.innerHTML=hours +"<img src='images/hm.png' style='margin:0 10px;' width='12' height='40'/>"+ minutes+"<img style='margin:0 10px;' src='images/ms.png' width='12' height='40'/>"+ seconds;
setTimeout("getTime()",500);
}
function formatTime(i){
if(i<10&&i==1){
i= "<img src='images/0.png' width='40' height='60'/>"+"<img src='images/1.png' width='20' height='60'/>";
}else if(i<10&&i!=1){
i= "<img src='images/0.png' width='40' height='60'/>" + "<img src='images/"+i+".png' width='40' height='60'/>";
}else{
var j= i.toString().charAt(0);
var z =i.toString().charAt(1);
if(j<10 && z<10&&j!=1&&z!=1){
i = "<img src='images/"+j+".png' width='40' height='60'/>" + "<img src='images/"+z+".png' width='40' height='60'/>";
}else if(j<10 && z<10&&j==1&&z!=1){
i = "<img src='images/1.png' width='20' height='60'/>" + "<img src='images/"+z+".png' width='40' height='60'/>";
}else if(j<10 && z<10&&z==1&&j!=1){
i = "<img src='images/"+j+".png' width='40' height='60'/>"+"<img src='images/1.png' width='20' height='60'/>";
}else if(j<10 && z<10&&(j==1&&z==1)){
i="<img src='images/1.png' width='20' height='60'/>"+"<img src='images/1.png' width='20' height='60'/>";
}
}
return i;
}
</script>
<center><br><br><br>
<div id="time"></div>
</center>
</body>
</html>