2016-06-21 13 views
0

「リセット」ボタンでクリックされた場合、他のボタンの値が変更されます。私はdocument.getelementbyidプロパティを使用しようとしましたが、うまくいかないようです。私はこれをどのように実装すべきか誰かが知っていますか?文書IDによるJavaScript設定値

function reset() { 
    stop(); 
    x.reset(); 
    update(); 
    opnieuw = setTimeout(function(){ 
    document.getElementById("scherm3").style.display = "block"; 
    document.getElementById("scherm2.2").style.visibility = "hidden"; 
    }, 10000);  
    clearTimeout(timeOut); 
    clearTimeout(timeOutElse); 
    document.getElementById("buttontimer").value = "Start"; 
} 

setTimeout(start, 5000); 

function toggleTimer(event) { 
if (isTimerStarted) { 
    stop(); 
    event.target.value = 'Start'; 
    timeOut = setTimeout(function(){ 
    document.getElementById("scherm4").style.visibility = "visible"; 
    document.getElementById("scherm2.2").style.visibility = "hidden"; 
    }, 4000) 
    clearTimeout(opnieuw); 
    clearTimeout(timeOutElse); 
    } 
    else { 
    start(); 
    event.target.value = 'Stop'; 
    timeOutElse = setTimeout(function(){ 
    document.getElementById("scherm3").style.display = "block"; 
    document.getElementById("scherm2.2").style.visibility = "hidden"; 
    }, 8000) 
      clearTimeout(timeOut); 
    clearTimeout(opnieuw); 
    } 
} 

とHTML:

<div id="button1"><input type="button" value="Stop" onclick="toggleTimer(event); clicks5times();" id="buttontimer"></div>  
     <input type="button" value="Opnieuw" onclick="reset()" class="button2" id="opnieuw"> 
+3

あなたのhtmlは何ですか? – everton

+1

あなたは決して呼び出されないリセット関数、定義されていない開始関数のsetTimeout、決して呼び出されないtoggleTimer関数を持っています。あなたが持っているものすべてを投稿し、それがしていないことをあなたが望むものを記述すると、役に立つ答えを得るかもしれません。 –

+0

@EvertonAgner私の投稿を編集する! – annaneedshelp

答えて

1

あなたはおそらく別に、単に「スタート」および「停止」ボタンを持っていることによって、あなたのコードを簡単に、そしてただの正しいボタンを表示/非表示ができ現在のコンテキスト。すでにリセットボタンを表示しています。これを「停止」ボタンにしてください。 「開始」をクリックすると、「開始」ボタンが非表示になり、「停止」ボタンが表示されます。 「停止」をクリックすると「停止」が表示されず、「開始」が表示されます。グローバルなブール値を使用して状態を追跡し、「停止」ボタンを「一時停止」ボタンのように動作させ、タイマーを0に戻す追加の「リセット」ボタンを表示することもできます。達成しようとしている。

+1

それはうまくいきました、ありがとう! – annaneedshelp

関連する問題