$(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
我用一些解释编辑我的帖子 –