时钟在JavaScript中 [英] clock in javascript
问题描述
有没有办法使用
javascript在网页中显示滴答时钟?但不是在文本框中,而是作为文本,我可以更改
样式,字体等。
cenk tarhan
is there a way to display a ticking clock in a web page using
javascript? but not in a textbox, rather as text that i can change the
style, font etc.
cenk tarhan
推荐答案
ce *** *********@gmail.com 写道:
是否有办法在网页中显示滴答时钟
javascript?但不是在文本框中,而是作为文本,我可以更改
样式,字体等。
is there a way to display a ticking clock in a web page using
javascript? but not in a textbox, rather as text that i can change the
style, font etc.
< http:// www .dynamicdrive.com / dynamicindex6 / clock2.htm>
请参阅< http://www.dynamicdrive.com/dynamicindex6/以获取更多
<http://www.dynamicdrive.com/dynamicindex6/clock2.htm>
see <http://www.dynamicdrive.com/dynamicindex6/for more
非常感谢VK,有史以来最快的回复!
thanks a lot VK, for the qucikest reply ever!
ce ************ @ gmail.com 写道:
是否可以使用
javascript在网页中显示滴答时钟?但不是在文本框中,而是作为文本,我可以更改
样式,字体等。
cenk tarhan
is there a way to display a ticking clock in a web page using
javascript? but not in a textbox, rather as text that i can change the
style, font etc.
cenk tarhan
< html>
< head>
< title>时钟< / title>
< / head>
< body>
< body>
< div id =''clock''class =''somecssstyle ''>< / div>
< script langage =''javascript :-P''type =''text / javascript''>
var months = new Array(January,February,Mararch,April,
" May",June,Julu ;,August,September,October,November,
" December");
var calDays = new Array( 星期日,星期一,星期二,星期三,
星期四,星期五,星期六);
var cloc kID = document.getElementById(''clock'');
函数pad(i){
//简单函数只需在前面加零数字较少
比零(所以我们得到12:05而不是12:5)
if(i< 10){
i =" 0" + i;
}
return(i);
}
函数doClock(){
setTimeout(" doClock()",1000);
t = new Date( );
m = t.getMonth();
d = t.getDay();
dt = t.getDate();
y = t.getFullYear();
h = t.getHours();
if(h< 12){
ap =" AM";
} else {
ap =" PM";
h = h-12;
}
mn = pad(t.getMinutes());
s = pad(t.getSeconds());
if(h == 0){
h = 12
}
clockID.innerHTML = calDays [d] +"," +月[M] +" " + dt +"
" + y +"< BR>" + h +":" + mn +":" + s +" + ap;
}
doClock()
< / script>
< / body>
< / html>
新年快乐 - 否则!
-
http://www.hunlock.com - - Javascript,CSS中的冥想。
<html>
<head>
<title>Clock</title>
</head>
<body>
<body>
<div id=''clock'' class=''somecssstyle''></div>
<script langage=''javascript :-P'' type=''text/javascript''>
var months=new Array("January", "February", "Mararch", "April",
"May", "June", "Julu", "August", "September", "October", "November",
"December");
var calDays=new Array("Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday");
var clockID = document.getElementById(''clock'');
function pad(i) {
//simple function to just add a zero in front of numbers less
than zero (so we get 12:05 instead of 12:5)
if (i < 10) {
i = "0"+i;
}
return(i);
}
function doClock() {
setTimeout( "doClock()", 1000 );
t = new Date();
m = t.getMonth();
d = t.getDay();
dt = t.getDate();
y = t.getFullYear();
h = t.getHours();
if (h < 12) {
ap="AM";
} else {
ap="PM";
h=h-12;
}
mn= pad(t.getMinutes());
s = pad(t.getSeconds());
if (h==0) {
h = 12
}
clockID.innerHTML=calDays[d]+", "+months[m]+" "+dt+"
"+y+"<BR>"+h+":"+mn+":"+s+" "+ap;
}
doClock()
</script>
</body>
</html>
Happy new year -- or else!
--
http://www.hunlock.com -- Musings in Javascript, CSS.
这篇关于时钟在JavaScript中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!