在下面的代码中,我想创建一个文本输入字段(用于日期),该字段被执行以便倒数计时器设置为该值并开始计数 - 例如,单击“确定“按钮。我真的不知道如何修改第一个变量才能做到这一点。从倒计时函数中的文本输入执行代码
<script>
// Set the date we're counting down to
var countDownDate = new Date("May 25, 2018 11:30:00").getTime();
// 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 days, 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"
document.getElementById("demo").innerHTML = "Pozostało: </br>" + days + " Dni, </br>" + hours + "g : " + minutes + "m : " + seconds + "s";
document.getElementById("demo").style.fontSize = "45px";
document.getElementById("demo").style.fontWeight = "bold";
document.getElementById("demo").style.color = "white";
document.getElementById("demo").style.backgroundColor = "#4783bf";
document.getElementById("demo").style.textAlign ="center";
// If the count down is finished, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "EXPIRED";
}
}, 1000);
</script>
谢谢你的所有建议!
据我所知,你想添加一个输入日期字段。点击确定按钮后,它会显示不同的时间,对吧? – Tomato32
你好, 确切地说,在点击OK后输入的数据字段执行执行日期并从该日期开始倒计时。 – kub4w0
您使用Datetimepicker或只是输入字段与特定的格式? – Tomato32