我是JavaScript的新手,我在使用etInterval()
時遇到問題。模擬時鐘的setInterval()
我正在創建一個模擬時鐘作爲練習。我有一個功能setTime()
,通過相應地旋轉箭頭來獲取並顯示時間。
我想一次又一次地執行這個函數。
這裏是我的代碼:
$(document).ready(function(){
function setTime(){
var d = new Date();
var hour = d.getHours();
var minute = d.getMinutes();
var hourRotation = hour * 30 + (minute/2);
var minuteRotation = minute * 6;
$("#small").css({
"-webkit-transform": "rotate(" + hourRotation + "deg)",
"-moz-transform": "rotate(" + hourRotation + "deg)",
"-o-transform": "rotate(" + hourRotation + "deg)"
});
$("#big").css({
"-webkit-transform": "rotate(" + minuteRotation + "deg)",
"-moz-transform": "rotate(" + minuteRotation + "deg)",
"-o-transform": "rotate(" + minuteRotation + "deg)"
});
};
function clockStart(){
setInterval(setTime(),1000);
setTime();
}
clockStart();
});
我想了解這種方法,以及如何使用它。我能找到的例子看起來很明顯,但我仍然無法完成工作。
好了吧!非常感謝你,有時候最簡單的事情會讓你陷入困境。美好的一天。 –