在下面的代碼中,我想創建一個文本輸入字段(用於日期),該字段被執行以便倒數計時器設置爲該值並開始計數 - 例如,單擊「確定「按鈕。我真的不知道如何修改第一個變量才能做到這一點。從倒計時函數中的文本輸入執行代碼
<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