javaScript警报和提示框将我重定向到另一个页面,上面写着“;找不到文件”;

javaScript alert and prompt boxes redirect me to another page that says "file not found"

本文关键字:文件 找不到 另一个 提示 重定向 javaScript      更新时间:2024-05-14

编程一个简单的网页,但当我使用JavaScript警报和提示框时,我会被随机引导到另一个屏幕,上面写着"找不到文件"。当我在Java脚本提示框上使用回车键说"好"时,就会发生这种情况,而我只需单击警报框的"好"即可。我该怎么解决这个问题?为什么会发生这种情况?HTML代码

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

如注释所述:

提交需要一个服务器来处理您的请求。因此,为了让它发挥作用,你必须将你的项目上传到ASP.net开发服务器或在本地设置一个。