我希望为 JavaScript 函数中的某些文本设置不同的 CSS 样式。
例如,将图像中建议的样式设置为附加代码。一些忠告?
// Set the date we're counting down to
var nowDate = new Date();
var countDownDate = new Date(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate(), 15, 30, 0, 0);
// Update the count down every 1 second
var x = setInterval(function() {
// Get todays date and time
var now = new Date().getTime();
// Find the distance between now an the count down date
var distance = countDownDate - now;
// Time calculations for hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Display the result in the element with id="demo"
if (hours >= 1) {
document.getElementById("shipping-countdown").innerHTML = "Order within " + hours + "h " +
minutes + "m " + seconds + "s " + "to have your order shipped on " // date of shipment;
} else if (hours < 1 && minutes < 1) {
document.getElementById("shipping-countdown").innerHTML = "Order within " + seconds + "s " +
"to have your order shipped on " // date of shipment;
} else {
document.getElementById("shipping-countdown").innerHTML = "Order within " + minutes + "m " +
seconds + "s " + "to have your order shipped on " // date of shipment;
}
})
<!-- Display the countdown timer in an element -->
<p id="shipping-countdown"></p>
慕姐4208626
慕妹3146593
幕布斯6054654
相关分类