【发布时间】:2019-10-02 22:17:43
【问题描述】:
我制作了一个 java-script 倒计时计数器并使用此行显示分钟和秒
document.getElementById("demo").innerHTML = Number(this.minutes) + 'm' + Number(this.seconds) + 's ';
但在 ios 中,由于这条线,它向我显示了 NANm NAN。所以我想用其他方式来显示分钟和秒。
这是我的打字稿代码。
if ((this.Fajardistance <= '59') && (this.Fajardistance >= '0')) {
let current_datetime = new Date()
let formatted_date = current_datetime.getFullYear() + "-" + (current_datetime.getMonth() + 1) + "-" + current_datetime.getDate()
console.log("formatted_date", formatted_date);
// Set the date we're counting down to
var countDownDate = new Date(`${formatted_date.toString()} ${value.fajar_iqamah}`).getTime();
console.log("countDownDate", countDownDate);
// Update the count down every 1 second
this.interavalTime = setInterval(function () {
// Get todays date and time
var now = new Date().getTime();
// Find the distance between now and the count down date
var distance = countDownDate - now;
this.testing = false;
// Time calculations for days, hours, minutes and seconds
this.minutes = Math.floor((Number(distance) % (1000 * 60 * 60)) / (1000 * 60));
this.seconds = Math.floor((Number(distance) % (1000 * 60)) / 1000);
//In these consoles minutes and seconds are as desired output just want to show them
console.log("Minutes:", this.minutes);
console.log("Seconds:", this.seconds);
//I was using this line to display minutes and seconds but it's incorrect way to display in ios devices.
//document.getElementById("demo").innerHTML = Number(this.minutes) + 'm' + Number(this.seconds) + 's ';
// // If the count down is over, write some text
if (distance < 0) {
clearInterval(this.interavalTime);
document.getElementById("demo").style.display = "none";
}
//console.log("Inside notification function outside if");
}, 1000);
}
主页.Html
<!--<span mode="md" id="demo" style="text-align:right;font-size: 16px; display:inline-block;margin-left: 16px; margin-top: 0px; color:red;"></span>-->
我之前使用上面注释的方法来显示,但它不是 ios 的正确方法。
【问题讨论】:
标签: typescript ionic3 angular5