脚本没有执行,脚本不起作用

时间:2015-06-30 18:48:04

标签: javascript

我是编码的新手,我试图创建一个“预订表”,以便人们填写他们的详细信息来预订游戏。 我已经整理了一些脚本,以便在用户点击按钮时显示游戏的名称和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>

1 个答案:

答案 0 :(得分:3)

如果你调用getElemtentByID,你也需要设置一个ID,添加 [XmlRoot("Custom")] public class Custom { [XmlElement("CustomDataType")] public CustomDataType customDataType { get; set; } } [XmlRoot("CustomDataType")] public partial class CustomDataType { [XmlAttribute("AttrField")] public string attrField { get; set; } [XmlAttribute("Value")]] public string value {get;set;} } 并且是的,在你的函数声明之后你错过了一个。