0
私は00:00:00 hmsフォーマットでユーザが何時間か入力するとカウントダウンが始まるプロジェクトのカウントダウンタイマーを作りたいと思っています。私は、この複雑にしている知っているjavascriptのマニュアルカウントダウンタイマー(ユーザ入力に基づいて)
// Wait for user to click the button before reading the value
window.onload=function(){
\t var work = document.getElementById("dl");
\t work.addEventListener("click", handler);
}
function handler() {
\t
\t \t //taking user input
\t \t var time1 = document.getElementById('hms').value;
\t \t //splitting it to seperate variables
\t \t var pieces = time1.split(":");
\t \t
\t \t var hours = pieces[0];
\t \t var minutes = pieces[1];
\t \t var seconds = pieces[2];
\t \t
\t \t //just calculating total number of seconds
\t \t seconds = seconds + minutes*60 + hours*3600;
\t \t
\t \t var tot = seconds + minutes*60 + hours*3600;
\t \t
\t \t // Save the interval's handle to `timer`
\t \t var timer = setInterval(countdown, 1000);
\t \t function countdown() {
\t \t var container = document.getElementById('count');
\t \t
\t \t var counter = 0, k=1, j=1, i=0, s1= pieces[2];
\t \t
\t \t //loop to print the timer
\t \t for(i=0; i<tot; i++){
\t \t \t if(seconds>0){
\t \t \t counter ++ ;
\t \t \t if(counter==60*k){
\t \t \t \t minutes--;
\t \t \t \t k++;
\t \t \t }
\t \t \t if(counter==3600*j){
\t \t \t \t hours--;
\t \t \t \t j++;
\t \t \t }
\t \t \t
\t \t \t container.innerHTML = 'Please wait <b>' + hours + '</b> hours, <b>' + minutes + '</b> minutes, <b>' + seconds + '</b> seconds';
\t \t \t }//end of if
\t \t \t else {
\t \t \t container.innerHTML = 'Time over';
\t \t \t clearInterval(timer);
\t \t \t }
\t \t }
\t \t
\t \t /* seconds--;
\t \t if (seconds > 0) {
\t \t \t container.innerHTML = 'Please wait <b>' + seconds + '</b> seconds..';
\t \t \t } else {
\t \t \t container.innerHTML = 'Time over';
\t \t \t clearInterval(timer);
\t \t \t } */
\t \t }
\t }
<input type="text" id="hms" placeholder="enter in the format 00:00:00 " />
\t <input type="button" id="dl" value="Start" />
\t <div id="count"></div>
は、誰かがそれを簡単にしてくださいすることができます次に何をすべきか迷ってしまいました半分正しいことと?それは大きな助けになります、ありがとう!
「_i'mはNEXT_何をするかを失った」 - > 1.(コンソールに示されている)エラーを修正し、2は、どのような「ハーフcorrect_ある_someコードは」 – Andreas
が行わ意味を説明してください。半正解はそれが動作することを意味しますが、私はそれをしたい方法ではありません – Hy2703
あなたのロジックは秒とtot計算の間で間違っています。あなたは時間と分を2回追加しています –