2017-12-07 4 views
1

ユーザが入力した番号を変換するためにボタンをクリックした後に、入力フィールドをクリアする必要があります。私はこれを理解するのが困難な時が来ています。もし誰かが私が非常に簡単な解決策であると感じるのを助けることができれば、私の頭を包み込むことはできません。ボタンをクリックした後に入力フィールドをクリアしようとしています

(function() { 
     //Constants 
     const KM_TO_MILES = 0.625; 
     const MILES_TO_KM = 1.6; 

     var user = prompt("So..What's your name beautiful?"); 
     if (user === null) { 
      alert("NOOOOO, you cancel me? meanie.") 
      remove(); 
     } 

     //on load function 
     window.onload = function() { 
      var result = document.getElementById("result"); 
      //display the user's name with a message prompt to continue to enter a distance 
      result.innerHTML = "Okay, " + user + ", enter your distance and I will calculate for you, don't worry."; 
      document.getElementById("convertBtn").onclick = startConvert; 

     }; 
     //on load function done 

     //conversion function 
     function startConvert() { 
      var placeholder = document.getElementById("distance").value; 
      var distanceInput = document.getElementById("distance").value; 
      var conversion = document.getElementById('List').value; 
      document.getElementById("List").value; 

      // If the user doesn't input a number run the alert 
      if ((placeholder === "") || (conversion == "Select Types")) { 

       alert("You didn't enter anything mate"); 
       // If the user inputs a number and clicks KM to M then calculate it and in the html page change the text to show the answer. 
      } else if (conversion == "Kilometers to Miles") { 

       document.getElementById("result").innerHTML = "Okay, " + user + " ,the distance of " + distanceInput + " is equal to " + (distanceInput * KM_TO_MILES + " miles."); 

       // If the user inputs a number and clicks M to KM then calculate it and in the html page change the text to show the answer. 
      } else if (conversion == "Miles to Kilometeres") { 


       document.getElementById("result").innerHTML = "Okay, " + user + " ,the distance of " + distanceInput + " is equal to " + (distanceInput * MILES_TO_KM + " kilometers."); 

      } 


     } 
     //conversion function done 



    }()); 
+1

だろうあなたのボタンをクリックしたときに、このイベントを呼び出す意味*「ページをリセットしますか」? – Phil

+1

「ページをリセットする」という意味がわかりません。入力フィールドをクリアするには、変換後に 'document.getElementById(" distance ")。value = '''を実行できます。 – KKK

+0

それはまさに私が意味するものではありません、私はそれをクリアしようとしましたが、それは私の答えはゼロになります。その他の提案はありますか? – Kam

答えて

0
document.getElementById('yourid').value = ''; 

あなたは確かにそれが*何作品

関連する問題