js和php显示时间但是不刷新,我想要它自动刷新
这个是代码<spanid="serverTime"></span><scripttype="text/javascript"language="javascript">f...
这个是代码
<span id="serverTime"></span>
<script type="text/javascript" language="javascript">
function show(){
var serverDate='<?php echo date("Y-m-d H:i:s");?>'
var year=serverDate.substr(0,4);
var month=serverDate.substr(5,2);
var day=serverDate.substr(8,2);
var hours=serverDate.substr(11,2);
hours=parseInt(hours)+8;
var minutes=serverDate.substr(14,2);
var seconds=serverDate.substr(17,2);
var localTimeSpan = document.getElementById("serverTime");
localTimeSpan.innerHTML =document.write("现在是"+year+"年"+month+"月"+day+"日"+hours+":"+minutes+":"+seconds);}
setTimeout(show,1000);
</script> 展开
<span id="serverTime"></span>
<script type="text/javascript" language="javascript">
function show(){
var serverDate='<?php echo date("Y-m-d H:i:s");?>'
var year=serverDate.substr(0,4);
var month=serverDate.substr(5,2);
var day=serverDate.substr(8,2);
var hours=serverDate.substr(11,2);
hours=parseInt(hours)+8;
var minutes=serverDate.substr(14,2);
var seconds=serverDate.substr(17,2);
var localTimeSpan = document.getElementById("serverTime");
localTimeSpan.innerHTML =document.write("现在是"+year+"年"+month+"月"+day+"日"+hours+":"+minutes+":"+seconds);}
setTimeout(show,1000);
</script> 展开
2个回答
展开全部
<meta http-equiv="Content-Type" Content="text/html; charset=utf-8" />
<span id="serverTime"><?php echo date("现在是Y年n月d日H:i:s")?></span>
<script type="text/javascript" language="javascript">
var serverTs = <?php echo time()?>;
var sec = 0;
function showTime(){
sec = sec+1;
var serverTsm = (serverTs+sec)*1000;
var date = new Date();
date.setTime(serverTsm);
var year = date.getFullYear();
var month = date.getMonth()+1;
var day = date.getDate();
var hour = date.getHours();
var min = date.getMinutes();
var second = date.getSeconds();
var localTimeSpan = document.getElementById("serverTime");
localTimeSpan.innerHTML = "现在是"+year+"年"+month+"月"+day+"日"+hour+":"+min+":"+second;
}
setInterval("showTime()",1000);
</script>
展开全部
<span id="serverTime"></span>
<script type="text/javascript" language="javascript">
function show(){
var serverDate=new Date();
var year=serverDate.getFullYear();
var month=serverDate.getMonth();
month=month<10?"0"+month:month;
var day=serverDate.getDate();
day=day<10?"0"+day:day;
var hours=serverDate.getHours();
hours=hours<10?"0"+hours:hours;
var minutes=serverDate.getMinutes();
minutes=minutes<10?"0"+minutes:minutes;
var seconds=serverDate.getSeconds();
seconds=seconds<10?"0"+seconds:seconds;
var localTimeSpan = document.getElementById("serverTime");
localTimeSpan.innerHTML ="现在是"+year+"年"+month+"月"+day+"日"+hours+":"+minutes+":"+seconds;
setTimeout(show,1000);}
show();
</script>
<script type="text/javascript" language="javascript">
function show(){
var serverDate=new Date();
var year=serverDate.getFullYear();
var month=serverDate.getMonth();
month=month<10?"0"+month:month;
var day=serverDate.getDate();
day=day<10?"0"+day:day;
var hours=serverDate.getHours();
hours=hours<10?"0"+hours:hours;
var minutes=serverDate.getMinutes();
minutes=minutes<10?"0"+minutes:minutes;
var seconds=serverDate.getSeconds();
seconds=seconds<10?"0"+seconds:seconds;
var localTimeSpan = document.getElementById("serverTime");
localTimeSpan.innerHTML ="现在是"+year+"年"+month+"月"+day+"日"+hours+":"+minutes+":"+seconds;
setTimeout(show,1000);}
show();
</script>
追问
追答
你没注意看我给你的代码,和你之前的差别很大,你最好全部拷过去测试。localTimeSpan.innerHTML ="现在是"+year+"年"+month+"月"+day+"日"+hours+":"+minutes+":"+seconds;
去掉document.write就不会出现了,另外要获得服务器时间,只能用ajax来实现。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询