$(document).ready(function() {
function currentDate() {
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth();
var day = now.getDay();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
var time = hours + ":" + minutes + ":" + seconds;
var date = (day + "/" + month + "/" + year).toLocaleDateString();
$('#time').html("<span class='glyphicon glyphicon-time'></span> " + time);
$('#date').html("<span class='glyphicon glyphicon-calendar'></span> " + date);
}
currentDate();
setInterval(currentDate(), 1000);
});
此代碼似乎沒有做任何事情......沒有錯誤... 它已被鏈接在'頭部'。jQuery日期和時間不修改HTML文檔
<script src="js/datetime.js"></script>
我的元素是:
<div class="navbar-right" style="color:#fff;margin-right:0px;">
<div class="navbar-brand" id="fade">
<p id="date" title="Your Date."></p>
</div>
<div class="navbar-brand" id="fade">
<p id="time" title="Your Time."></p>
</div>
</div>
的網頁似乎並沒有顯示任何東西,都在它應該去的地方。
請不要發佈唯一代碼的答案。請解釋你的答案。 – phts
我用一些解釋編輯我的帖子 –