我试图在分钟内得到的只有这些值,00 15 30和45,我们如何才能解决这个问题?我需要像下面的截图.
的数据
下面的代码可以工作,但我不能隐藏00和15之间的值,15和30,30和45。有人知道如何修复吗?
先谢谢你了。
// Add an event listener for when the input changes
timeInput.addEventListener('input', function() {
// Get the current value of the input
var currentTime = timeInput.value;
// Split the current time into hours and minutes
var parts = currentTime.split(':');
var hours = parseInt(parts[0]);
// Set the minutes to the nearest 15-minute interval
var minutes = 0;
var currentMinutes = parseInt(parts[1]);
if (currentMinutes >= 0 && currentMinutes < 8) {
minutes = 0;
} else if (currentMinutes >= 8 && currentMinutes < 23) {
minutes = 15;
} else if (currentMinutes >= 23 && currentMinutes < 38) {
minutes = 30;
} else if (currentMinutes >= 38 && currentMinutes < 53) {
minutes = 45;
} else {
minutes = 0;
hours += 1;
}
// Format the adjusted time
var adjustedTime = (hours < 10 ? '0' : '') + hours + ':' + (minutes < 10 ? '0' : '') + minutes;
// Set the adjusted time back to the input
timeInput.value = adjustedTime;
});
个字符
1条答案
按热度按时间qni6mghb1#
个字符