tbar : [{
xtype: 'label',
id: 'lbl-now-date',
fieldLabel: '您好,今天是',
text: getNowDate()
},'->',{
xtype : 'button',
text : 'OA登陆',
iconCls : 'add'
},'-',
{
xtype : 'button',
text : '设为首页'
},
'-',{
xtype : 'button',
text : '加入收藏'
}],
原来setTimeout去掉~
定时刷新时间也不是用setTimeout, setTimeout只执行一次, 要用setInteval
在后面加一段
setInterval(function(){
var lbl = Ext.getCmp('lbl-now-date')
if (lbl) lbl.text = getNowDate()
}, 1000)
因为js代码是从上到下执行的,所以var clock = document.getElementById("myclock")
找不到元素
clock是空的
所以可以将js代码放到div后面,也可以将 var clock = document.getElementById("myclock")
定义放到 setInterval的function里
如:
<script type="text/javascript" language="javascript">
setInterval(function (){
var clock = document.getElementById("myclock")
var d = new Date()
clock.innerHTML = d.getHours() + ":" + d.getMinutes() + ":" +d.getSeconds()
},1000)
</script>
<div id="myclock">
00:00:00
</div>
<html><head>
<script language="JavaScript">
function showTime()
{
var currentDate = new Date()
var hours = currentDate.getHours()
var minutes = currentDate.getMinutes()
var seconds = currentDate.getSeconds()
//
//格式化输出
//
if (minutes <10)
minutes = "0" + minutes
if (seconds <10)
seconds = "0" + seconds
var currentTimeString ="<font color=blue>" + hours + ":" + minutes + ":" + seconds + "</font>"
document.getElementById("show").innerHTML=currentTimeString //改这地方
window.setTimeout("showTime()", 1000)
}
</script>
</head>
<body onload="showTime()">
<span id="show"></span> <!--加这地方-->
</body>
</html>