Safariにエラーはなく、Chromeで完全に動作しています。数字はSafariには表示されません。私はSafariとChromeのモバイル版もチェックしましたが、どちらも動作していません。私は正直なところ、何が間違っているかを知ることはできません。何かを間違ってフォーマットしてしまって、Chromeがそれを自動的に補います。なぜこのカウントダウンJavaScriptはクロム以外のブラウザでも動作しません
コード自体はかなり基本的なもので、2つのdatetimeを取り、日、時間、分、秒の数を保持するオブジェクトに変換する単純な関数です。次に、もう1つの関数はちょうど1秒間隔で呼び出され、データを正しい要素に入れます。
は、ここで私はあなたがFirefoxでコンソールでこれを入れたときに、それがNaN
新しいTimeTill(思い付くことに気づいたライブサイトhttps://zeiworld.net/countdown.php
またはそれ自体によってコードhttps://jsfiddle.net/4b9py0sg/1/
$(function(){
function TimeTill(startDate, targetDate, floor){
//Set the starting information
var now = startDate;
var tar = Date.parse(targetDate);
var til = tar - now;
//Split the basic millieseconds between each date into days with a decimal
var days = til/1000/60/60/24;
//Take the decimal from days and multiply it by the hours in a day
var hours = (days % 1) * 24;
//Take the decimal from hours and multiply it by the minutes in an hour
var minutes = (hours % 1) * 60;
//Take the decimal from minutes and multiply it by the seconds in a minute
var seconds = (minutes % 1) * 60;
//Store each value in its respective property, flooring it if required
if (floor == true){
this.days = Math.floor(days);
this.hours = Math.floor(hours);
this.minutes = Math.floor(minutes);
this.seconds = Math.floor(seconds);
}else{
this.days = days;
this.hours = hours;
this.minutes = minutes;
this.seconds = seconds;
}
}
function updateScreen(){
//Store the time between two dates in an object
launchIn = new TimeTill(Date.now(), '2016-04-15 20:00:00 CDT', true);
//Output the time parts to their respective divs
$('.days').html(launchIn.days);
$('.hours').html(launchIn.hours);
$('.minutes').html(launchIn.minutes);
$('.seconds').html(launchIn.seconds);
}
//Start and continue Loop
updateScreen();
setInterval(updateScreen, 1000);
});
私はfirefoxをインストールして見ています – Zei