想要在页面上显示当前时间,并且应该更改该时间,而无需单击浏览器的刷新按钮 [英] want to show current time on the page and that should be changed without click on the refresh button of browser
本文介绍了想要在页面上显示当前时间,并且应该更改该时间,而无需单击浏览器的刷新按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
想要在页面上显示当前时间,并且应该更改该时间,而无需单击浏览器的刷新按钮.为此,我使用更新面板,时间在标签上显示了我的时间,但是我希望它可以刷新自己,并且时间应该自行更改...帮助我
want to show current time on the page and that should be changed without click on the refresh button of browser.for this i m using update panel and time is showing by me on the label but i want that it should be refresh itself and time should be changed itself...help me
推荐答案
尝试使用此javascript
try using this javascript
function updateClock() {
var now = new Date(), // current date
months = ['January', 'February', '...']; // you get the idea
time = now.getHours() + ':' + now.getMinutes(), // again, you get the idea
// a cleaner whay than strin concatenation
date = [now.getDate(),
months[now.getMonth()],
now.getFullYear()].join(' ');
// set the content of the element with the ID time to the formatted string
document.getElementById('time').innerHTML = [date, time].join(' / ');
// call this function again in 1000ms
setTimeout(updateClock, 1000);
}
updateClock(); // initial call
问候,
爱德华
Regards,
Eduard
尝试一下..
<script type="text/javascript">
function show2(){
if (!document.all&&!document.getElementById)
return
thelement=document.getElementById? document.getElementById("tick2"): document.all.tick2
var Digital=new Date()
var hours=Digital.getHours()
var minutes=Digital.getMinutes()
var seconds=Digital.getSeconds()
var dn="PM"
if (hours<12)
dn="AM"
if (hours>12)
hours=hours-12
if (hours==0)
hours=12
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
var ctime=hours+":"+minutes+":"+seconds+" "+dn
thelement.innerHTML=ctime
setTimeout("show2()",1000)
}
window.onload=show2
</script>
<form id="form1" runat="server">
<div>
<p id="tick2"></p>
</div>
</form>
这篇关于想要在页面上显示当前时间,并且应该更改该时间,而无需单击浏览器的刷新按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文