gpt4 book ai didi

javascript - 脚本未执行并且脚本不工作

转载 作者:行者123 更新时间:2023-11-28 19:08:44 26 4
gpt4 key购买 nike

我是编码新手,我尝试创建一个“预订表单”,以允许人们填写详细信息来预订游戏。我编写了一些脚本来在用户单击按钮时显示游戏的名称和 ID。

但是(你猜怎么着!)它不起作用。

我们将非常感谢您的帮助。谢谢。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Games Library Reservations Page</title>
</head>
<body>
<div>
<h1>Reservations</h1>
</div>

<p><b>Wish to reserve a game? Just fill in this form:</b> </p>

<form name="reservationsForm">

<p><strong>Game ID</strong><br>
<input type="number" name="gameID" placeholder="1-8">

<button type="button" onclick="gameConfirmation()">Reserve a game!</button>
<p id="gameChosen"></p>

</form>
</div>

<script>
function gameConfirmation()
var id;

id = document.getElementById("gameID").value;

if (id == 1) {
document.getElementById("gameChosen").innerHTML = "You have selected to ``reserve game ID 1: Fantasy World.";
} else if (id == 2) {
document.getElementById("gameChosen").innerHTML = "You have selected to reserve game ID 2: Sir Wags A Lot.";
} else if (id == 3) {
document.getElementById("gameChosen").innerHTML = "You have selected to reserve game ID 3: Take A Path.";
} else if (id == 4) {
document.getElementById("gameChosen").innerHTML = "You have selected to reserve game ID 4: River Clean Up.";
} else if (id == 5) {
document.getElementById("gameChosen").innerHTML = "You have selected to reserve game ID 5: Pinball.";
} else if (id == 6) {
document.getElementById("gameChosen").innerHTML = "You have selected to reserve game ID 6: Ghost Girl.";
} else if (id == 7) {
document.getElementById("gameChosen").innerHTML = "You have selected to reserve game ID 7: Dress Up.";
} else if (id == 8) {
document.getElementById("gameChosen").innerHTML = "You have selected to reserve game ID 8: Where is my hat?.";
} else {
document.getElementById("gameChosen").innerHTML = "There is no game with that ID. Please try again.";
}
}
</script>
</div>

</body>

</html>

最佳答案

如果调用 getElemtentByID 还需要设置 ID,请添加 <input type="number" name="gameID" id="gameID" placeholder="1-8">是的,您在函数声明后缺少一个 {。

关于javascript - 脚本未执行并且脚本不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31146095/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com