2017-04-05 80 views
2

我知道這種類型的問題已被問到,但我發現的答案從未幫助過我的案例。 所以我有一個功能GameOverScreen()這導致點擊一個按鈕來重置所有內容。 當我點擊我的按鈕時,我的大部分代碼都完成了,但沒有一行:$('#gameOver').css('display', 'none');如果我想完成這個,我必須點擊幾次按鈕。需要點擊兩次或更多按鈕才能觸發功能

請注意,在我的HTML沒有click事件,這是一個簡單的p與裏面輸入:在您的幫助

<p>Pour recommencer la partie, cliquez sur le bouton :<input type="reset" id="restart" value="Recommencer"></p> 

謝謝, 這裏是我的jQuery代碼:

function gameOverScreen() { 
    $('#gameOver').css('display', 'block'); 
    propSound[0].pause(); 
    $('#restart').click(reset); 
}; 

function reset() { 

    //je remets mon bouton en position "on" 
    $('#start').css('margin-left', '0px'); 
    //mon avion reprend sa position initiale 
    planeHeight.css('display', 'block'); 
    planeHeight.css('top', '434px'); 
    planeHeight.css('transform', 'rotateZ(0deg)'); 
    //J'arrête l'animation de mon hélice 
    clearInterval(intervalIdAnimProp); 
    //J'arrête l'animation de mon bg 
    clearInterval(intervalIdanimBg); 
    //J'arrête le son 
    propSound[0].pause(); 
    //Le compteur se remet à zéro 
    speed = '000'; 
    $('#speedometer').val(speed); 
    //Désaffichage des mes flèches 
    $('#arrows').css('display', 'none'); 
    $('#display').val("Afficher"); 
    //background 
    $('#gameOver').css('display', 'none'); 
    bgSrc.css('background', 'url("sources/images/fond.jpg")'); 
}; 

編輯:這是我的HTML,如果有必要:

<html lang="fr"> 
<head> 
    <meta charset="UTF-8"> 
    <title>Mini jeux</title> 
    <script src="jquery-3.1.1.js"></script> 
    <script src="exercice17.js"></script> 
    <link rel="stylesheet" href="exercice17.css"> 
</head> 
<body> 
    <div id="main"> 

     <div id="playground"> 
      <div id="plane"> 
       <img src="sources/images/avion1.png"> 
       <img id="prop" src="sources/images/helice.png"> 
      </div> 
      <audio id="engine" src="sources/son/moteur.mp3" loop></audio> 
      <div id="arrows"> 
       <section id="up"><img src="sources/images/boutons.png"></section> 
       <section id="down"><img src="sources/images/boutons.png"></section> 
       <section id="right"><img src="sources/images/boutons.png"></section> 
       <section id="left"><img src="sources/images/boutons.png"></section> 
      </div> 
     </div> 

     <div id="cmd"> 
      <div id="onOff"> 
       <span>Démarrer/arrêter :</span> 
       <div id ="on"><img id="start" src="sources/images/on-off.png"></div> 
      </div> 
      <div id="compteur"> 
       <span>Vitesse :</span> 
       <input type="text" id="speedometer" value="000" size="1" max='270'> 
       <p>km/h</p> 
      </div> 
      <div id="instructions"> 
       <p>Après avoir démarrré, utilisez les flèches du clavier pour piloter l'avion. Sinon, vous pouvez activer/ désactiver les commandes tactiles : <input type="button" id="display" value="Afficher"></p>  </div> 
      <div id="flyButton"> 
      </div> 
     </div> 

     <div id="gameOver"> 
      <h1>GAME OVER</h1> 
      <p>Pour recommencer la partie, cliquez sur le bouton :<input type="reset" id="restart" value="Recommencer"></p> 
     </div> 

    </div> 

</body> 

+0

你也可以試試:'$( 「#復位)。在(」 點擊」,重設());' – px06

+0

謝謝您的快速答覆,但不爲我工作要麼... –

+0

你是否打開了瀏覽器控制檯?當reset()函數應該運行時,控制檯是否顯示任何內容? – px06

回答

0

我對此答案並不完全確定,但<input type="reset">用於將所有表單(如果有)重置爲默認值。我不認爲你在這裏試圖做到這一點。您可以嘗試將輸入按鈕的type改爲<input type="button">之類的東西嗎?

+0

謝謝你的回答,最後'visibily','hidden'起作用。 –

0

如果隱藏其可見性,它也可能更好地工作。 (不完全確定你的代碼看起來非常具體)。

喜歡的東西:

$('#gameOver').css('visibility', 'hidden'); 
+0

而獲勝者是...... :)謝謝你的作品!我不知道爲什麼'顯示''沒有'不起作用,但我從現在開始會想到這個解決方案! –

+0

甜。請upvote我,所以我實際上可以寫評論:D – Jamin

+1

那麼,如果你告訴我如何做到這一點,愉快! –

相關問題