2016-04-12 26 views
-2

編程一個簡單的網頁,但是當我使用JavaScript警報和提示框時,我隨機指向另一個顯示「找不到文件」的屏幕。當我使用回車鍵在Java腳本提示框上說「ok」時,隨時我只需點擊alert框的okay即可。我怎樣才能解決這個問題?爲什麼發生這種情況? HTML代碼javaScript警報和提示框將我重定向到另一個頁面,顯示「找不到文件」

<!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

請在您的問題中包含您的代碼 – jasonscript

+0

您正在使用哪種瀏覽器?哪個OS?你可能會有一些惡意軟件的干擾...安裝和運行一些體面的反病毒軟件;然後安裝可觀的瀏覽器,如Chrome,Firefox或Opera。 – argon

+0

谷歌Chrome瀏覽器,Windows 10.我做了病毒掃描,它出現100%清潔 –

回答

0

正如評論指出:

的提交需要一個服務器來處理您的請求。因此,要使其工作,必須將項目上傳到ASP.net開發服務器或在本地安裝一個。

相關問題