我一直在試圖獲得一個函數來重載每一秒。Javascript獲取文件內容循環
我可以用php獲取文件內容(和元頁面重新加載),但我也使用JS來顯示時間和它不是即時加載,所以它有一個閃爍的效果。
我試過這個與JS,但它什麼也沒有顯示。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Vivarium Enviroment Control Centre</title>
<link rel="stylesheet" href="style.css">
<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
<script type="text/javascript">
function updateTime() {
var currentTime = new Date();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
var seconds = currentTime.getSeconds();
if (minutes < 10){
minutes = "0" + minutes;
}
if (seconds < 10){
seconds = "0" + seconds;
}
var v = hours + ":" + minutes + ":" + seconds + " ";
if(hours > 11){
v+="PM";
} else {
v+="AM"
}
setTimeout("updateTime()",1000);
document.getElementById('time').innerHTML=v;
}
updateTime();
$("document").ready(function(){
setInterval(function(){
$("#wifi").load('wifiout.php');
},1000);
});
function changeStatus() {
var image = document.getElementById('lightStatus');
if (image.src.match("lightoff")) {
image.src = "lighton.png";
} else {
image.src = "lightoff.png";
}
}
</script>
</head>
<body>
<div id="topbar">
<span id="time"></span>
<div id="wifi"></div>
<img id="lightStatus" class="right" onclick="changeStatus()" src="lightoff.png" width="32" height="32">
</div>
</body>
</html>
你正在使用jQuery語法,但我沒有看到它包括在內? –
這是我以前從未做過的事情,所以很有可能。 –