2
私はJavascriptの初心者です。私が書いたこのコードではいくつか問題があります。それは私のウェブサイトのためのデジタルタイムクロックを作成することになっています。シンプルなタイムクロックはエラーなしで動作しません
のCPGは、私の機能/変数名、それは私のウェブサイトの名前のためにその省略形:)
また、私は放火犯からNOコンソールエラーを取得していない午前ですので、私のJSLintは私のコードことを確認しているなぜあなたは迷っている場合vaildです。
は、ここでは、コードです:
(function() {
function CpgsClock() {
this.cpgsTime = new Date();
this.cpgsHour = this.cpgsTime.getHours();
this.cpgsMin = this.cpgsTime.getMinutes();
this.cpgsDay = this.cpgsTime.getDay();
this.cpgsPeriod = "";
}
CpgsClock.prototype.checker = function() {
if (this.cpgsHour === 0) {
this.cpgsPeriod = " AM";
this.cpgsHour = 12;
} else if (this.cpgsHour <= 11) {
this.cpgsPeriod = " AM";
} else if (this.cpgsHour === 12) {
this.cpgsPeriod = " PM";
} else if (this.cpgsHour <= 13) {
this.cpgsPeriod = " PM";
this.cpgsHour -= 12;
}
};
CpgsClock.prototype.setClock = function() {
document.getElementById('cpgstime').innerHTML = "" + this.cpgsHour + ":" + this.cpgsMin + this.cpgsPeriod + "";
};
var cpgsclock = new CpgsClock();
setInterval(function() {
cpgsclock.setClock();
cpgsclock.checker();
}, 1000);
})();
のでsetclockスクリプトメソッドが正常に動作します。しかし、チェッカーは何もしません。あなたが見ることができるように、それは時間をチェックし、AMとPMにそれに応じてそれを設定します。それは私にはありません。
助けがあれば助かります。
ああ、ありがとう!どのように私はそれもあまりにも欲しいの作品:) – Dropped43