所以我遵循一個非常直接的視頻教程,通過JS在你的網頁上添加一個時鐘。我有完全相同的代碼,但它不適用於我的。有什麼建議麼?謝謝!時鐘不工作?
這是我的代碼:
<body>
<div id="clockDisplay">00:00</div>
<!-- JAVASCRIPT starts here -------------------------------------------------------->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript" language="JavaScript">
$(window).load(function renderTime() {
var currentTime = new Date() ;
var diem = "AM" ;
var h = currentTime.getHours() ;
var m = currentTime.getminutes() ;
var s = currentTime.getSeconds() ;
if (h == 0) {
h = 12;
} else if (h > 12) {
h = h -12;
diem = "PM" ;
}
if (h < 10) {
h = "0" + h;
}
if (m < 10) {
m = "0" + m;
}
if (s < 10) {
s = "0" + s;
}
var myClock = document.getElementyID('clockDisplay');
myClock.textContent = h + ":" + m + ":" + s + " " + diem;
setTimeout(renderTime()' ,1000) ;
};
renderTime() ;
</script>
<!-- JAVASCRIPT ends here --------------------------------------------------------->
</body>
我不知道爲什麼人們需要jQuery的一個時鐘吳 – C5H8NNaO4 2013-02-19 16:29:18
@ Glutamat然後將不會使用它從dom中選擇... – Ryan 2013-02-19 16:30:01
FYI currentTime.getminutes()應該是currentTime.getMinutes() – 2013-02-19 16:32:29