我在为我的GCSE课程做的网站遇到了一些麻烦 - 我希望有人可以帮助我吗?我需要制作大约4个输入框,然后关联它们以使用户自定义警报。困惑我知道的东西;在这里,让我做一些糟糕的伪代码:
user INPUT box for game ID
user INPUT box for name
user INPUT box for start day of reservation
IF game ID > 8 || < 1
PRINT error message
ELIF game ID > 1 && < 8
PRINT corresponding game ID AND user name AND start date in an alert box
或者,这里有一些邋Python的Python代码:
x = input("Game ID: ")
y = input("Name: ")
z = input("Start Day of Reservation: ")
if (x > 8 && < 1):
print("Invalid Input")
elif x == 1:
print("Thank you, " + y + "for renting " + x + " from " + z")
#repeats elif code from 1-8 for individual game names.
有人可以帮忙吗?谢谢:))
答案 0 :(得分:0)
我猜你看起来像这样:
function handleForm() {
var gameId, gameName, startDate;
gameId = document.getElementById("gameId").value;
gameName = document.getElementById("gameName").value;
startDate = document.getElementById("startDate").value;
if (gameId > 8 || gameId < 1) {
alert("Error!");
} else {
alert(gameId + " " + gameName + " " + startDate);
}
}
<input type="text" id="gameId" placeholder="ID">
<input type="text" id="gameName" placeholder="Name">
<input type="date" id="startDate" placeholder="Start date">
<button onclick="handleForm()">Submit</button>
答案 1 :(得分:0)
如果我理解你,你需要这样的东西......
<html>
<head>
<script>
d = document;
function verifyData(i){
var gameid = d.getElementById('gameid_' + i).value,
name = d.getElementById('name_' + i).value,
date = d.getElementById('date_' + i).value;
if (i >= 1 || i <= 8){
if (gameid && name && date) alert('Thank you, ' + name + ', for renting ' + gameid + ' from ' + date);
else alert('All fields are required for verification.');
} else alert('Invalid Row.');
}
</script>
</head>
<body>
<input id="gameid_1" placeholder="Game ID" /><input id="name_1" placeholder="Game ID" /><input id="date_1" placeholder="Date" /><input onclick="verifyData(1);" type="button" value="Verify" /><br />
<input id="gameid_2" placeholder="Game ID" /><input id="name_2" placeholder="Game ID" /><input id="date_2" placeholder="Date" /><input onclick="verifyData(2);" type="button" value="Verify" /><br />
<input id="gameid_3" placeholder="Game ID" /><input id="name_3" placeholder="Game ID" /><input id="date_3" placeholder="Date" /><input onclick="verifyData(3);" type="button" value="Verify" /><br />
<input id="gameid_4" placeholder="Game ID" /><input id="name_4" placeholder="Game ID" /><input id="date_4" placeholder="Date" /><input onclick="verifyData(4);" type="button" value="Verify" /><br />
<input id="gameid_5" placeholder="Game ID" /><input id="name_5" placeholder="Game ID" /><input id="date_5" placeholder="Date" /><input onclick="verifyData(5);" type="button" value="Verify" /><br />
<input id="gameid_6" placeholder="Game ID" /><input id="name_6" placeholder="Game ID" /><input id="date_6" placeholder="Date" /><input onclick="verifyData(6);" type="button" value="Verify" /><br />
<input id="gameid_7" placeholder="Game ID" /><input id="name_7" placeholder="Game ID" /><input id="date_7" placeholder="Date" /><input onclick="verifyData(7);" type="button" value="Verify" /><br />
<input id="gameid_8" placeholder="Game ID" /><input id="name_8" placeholder="Game ID" /><input id="date_8" placeholder="Date" /><input onclick="verifyData(8);" type="button" value="Verify" /><br />
</body>
</html>
以下是一个实例:http://jsfiddle.net/ytpwkotd/1/