javaScript警报和提示框将我重定向到另一个页面,上面写着“;找不到文件”;
javaScript alert and prompt boxes redirect me to another page that says "file not found"
编程一个简单的网页,但当我使用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开发服务器或在本地设置一个。
相关文章:
- Angular 2:在本地.json文件上找不到文件
- 放大弹出生成“;找不到文件”;YouTube视频的错误
- Web 地址虚拟目录会断开外部 JavaScript 链接,因此找不到文件
- 找不到Intel XDK cordova文件api 1.3.3文件
- 按钮未运行为按钮,找不到如何使运行JS文件
- Spring 3.1 - 找不到 JavaScript 文件 - 404 错误
- javaScript警报和提示框将我重定向到另一个页面,上面写着“;找不到文件”;
- Cordova jsPDF-PDF生成,我在手机上找不到PDF文件
- 错误:找不到模块'html',可以't提供静态文件
- 在子网站/子文件夹中找不到SVG href ID
- 嵌套页找不到父.js文件
- 为什么浏览器可以'在`.中找不到js文件/lib/`(相对)位置
- 可以'在Angular应用程序中找不到引导文件
- Angular html文件可以'找不到JS控制器[Node.JS/Angular]
- 节点可以'找不到父node_modules文件夹中存在的模块
- angularjs生成器中的Coffeescapet在控制台中找不到js文件
- 外部JS文件找不到控件,但可以使用quickwatch
- Rails js.动词文件找不到方法“渲染”
- 在Django中使用url参数时,CSS + JS文件找不到(404)
- 捆绑 css 文件 - 找不到文件