2016-04-12 16 views
-2

Basit bir web sayfası programlama ancak JavaScript uyarısı kullandığımda ve kutuları sorduğumda rastgele "dosya bulunamadı" yazan başka bir ekrana yönlendirildim Java Komut Dosyası istemi kutusunda "tamam" demek için enter tuşuna bastığımda ve uyarı kutusu için her zaman tıklattığımda. Bunu nasıl düzeltebilirim? bu neden oluyor? HTML kod açıklamalarda belirtildiği gibijavaScript uyarısı ve bilgi kutuları beni "dosya bulunamadı" yazan başka bir sayfaya yönlendiriyor

<!DOCTYPE html> 
<html> 
    <title>BasketBall Game</title> 
    <link href ="styles.css" rel = "stylesheet" type ="text/css"> 
     <script type = "text/javascript" src = myScript.js> 
    </script> 
<body> 
    <div id = "mainbody"> 
    <h1>BaksetBall Game</h1> 
     <form id="frm1" action="form_action.asp" onsubmit="play()"> 
      <!--<label>Please Enter in Your Team Name:</label><input id="myInput" type="text" name="fname" size="20" autofocus placeholder="i.e. BYU" value ="" onkeydown = "if (event.keyCode == 13) document.getElementById('playButton').click()"><br>--> 
      <label>Please Enter in Your Team Name:</label><input id="myInput" type="text" name="fname" size="20" autofocus placeholder="i.e. BYU" value =""><br> 
      <!--<button id = "playButton" type = "submit" onclick="play()" value = "Play"> Play </button> --> 
      <button id = "playButton" type = "submit" >Play </button> 
      <button type = "button" onclick="reset()" value = "reset"> Reset</button><br> 
     </form> 

     <p id = "output"></p> 
    </div> 
    </body> 
</html> 





JAVASCRIPT CODE 
//function that will go through and play games between user schools and other schools 
function play() 
{ 
    //get user input on their team name 
    var x = document.getElementById("frm1"); 

    //create a new object of type Team and initialize values 
    var userTeam = new Team(null, 0, 0); 

    //assign team name 
    userTeam.Name = x.elements[0].value; 

    //check to make sure the user enters in their team name 
    if (userTeam.Name == "") 
    { 
     window.alert("Please enter in a team name"); 
     document.getElementById("myInput").select(); 
    } 
    else 
    { 
     //initialize some variables 
     var oppTeam = null; 
     var games = null; 
     var homeScore = 0; 
     var visitScore =0; 

     //prompt for number of games to be played 
     games = prompt("Please enter in how many games you want to play"); 

     //for loop to iterate through the games and keep track of userTeams wins and losses 
     for (var i =0; i < games; i++) 
     { 
      oppTeam = window.prompt("Please enter in an opposing team"); 
      //while loop to check against ties 
      while(homeScore == visitScore) 
      { 
       //call to random function to get scores between 0 and 100 
       homeScore = getRandomInt(0,100); 
       visitScore = getRandomInt(0,100); 
      } 

      //determine who wins and who losses, and keep track of data 
      if(homeScore > visitScore) 
      { 
       userTeam.wins = userTeam.wins +1; 
      } 

      else 
      { 
       userTeam.losses = userTeam.losses +1; 
      } 
     } 
     //print out the results of the games 
     document.getElementById("output").innerHTML = userTeam.Name +" Wins: "+ userTeam.wins + " Losses:"+ userTeam.losses; 
    } 
} 

//function to get random numbers 
function getRandomInt(min, max) 
{ 
    return Math.floor(Math.random() * (max - min)) + min; 
} 

//function to reset the game 
function reset() 
{ 
    document.getElementById("output").innerHTML = " "; 
    document.getElementById("frm1").reset(); 
    document.getElementById("myInput").select(); 

} 

//function to create the Team "class" 
function Team(Name, wins, losses) 
{ 
    this.Name = Name; 
    this.wins = wins; 
    this.losses = losses; 
} 
+1

Lütfen kodunuzu sorunuz içinde ekleyin – jasonscript

+0

Hangi tarayıcıyı kullanıyorsunuz? Hangi işletim sistemi? Bazı zararlı yazılım girişimleriniz olabilir ... Bazı saygın anti-virüs yazılımı yükleyin ve çalıştırın; Ardından Chrome, Firefox veya Opera gibi saygın bir tarayıcı yükleyin. – argon

+0

Google Chrome Tarayıcı, Windows 10. Bir virüs taraması yaptım ve% 100 temiz çıktı –

cevap

0

: teslim

bir sunucu isteğinizi işlemek için bekler. Bu yüzden çalışması için projenizi bir ASP.net geliştirme sunucusuna yüklemeniz veya yerel olarak kurmanız gerekir.

İlgili konular