我需要从 ajax 请求中调用代码,此调用是针对当前时间的。我不知道该怎么做,我设置了一个带有工作时钟的 html 文件。我调用的页面没有显示它从 $container1 加载文本的时钟,但没有显示时钟和日期?有谁知道为什么?如果容器 1 中的文本加载正常,为什么当前时间和日期时钟不工作?
到目前为止,我在 html 中拥有的数据是从中获取的。
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("1","2","3","4","5","6","7","8","9","10","11","12")
var date=new Date();
var hours=date.getHours();
var minutes=date.getMinutes();
var ampm = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12;
hours = hours ? hours : 12;
minutes = minutes < 10 ? '0'+minutes : minutes;
var s=date.getSeconds();
s = s < 10 ? '0'+s : s;
var Time = "Current Time: ";
var Text = "Last Updated: ";
document.getElementById('time').innerHTML =Time+" "+dayarray[day]+" "+montharray[month]+"/"+daym+"/"+year+" "+hours+":"+minutes+":"+s+" "+ampm;
document.getElementById('time2').innerHTML =Text+" "+dayarray[day];
}
}
</script>
</head>
<body>
<div id="container1">
<div id="left">By TrueLogic Company
<p>Edited By International Electronic Components</p>
</div>
<div id="right">
<div id="time2"></div>[LastBuuild]
<p>
<div id="time"></div>
</p>
</div>
</div>
</body>
</html>
在我希望它加载到的页面中,我尝试了几种方法,但这就是我现在所拥有的。
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
function refreshPage () {
var page_y = document.getElementsByTagName("body")[0].scrollTop;
window.location.href = window.location.href.split('?')[0] + '?page_y=' + page_y;
}
window.onload = function () {
setTimeout(refreshPage, 3000);
if (window.location.href.indexOf('page_y') != -1 ) {
var match = window.location.href.split('?')[1].split("&")[0].split("=");
document.getElementsByTagName("body")[0].scrollTop = match[1];
}
{
$('#container').load('C:/Program%20Files/TrueChem/Data/dashboard/src/Test.HTML #container1');
}
}
</script>
<div id="container">