基本上,我有一个带有清单输入清单的表单。如果一个用户选择其中一个输入并提交表单,则我不希望其他用户能够看到该选项。
我的第一个想法是在服务器上存储一个变量,将一个变量分配给每个输入。如果在提交表单时检查输入,则其分配的变量更改。然后使用如果其他任何时间加载页面来检查每个变量,并且已更改的所有变量,请保持隐藏。
。这是我到目前为止使用JavaScript所拥有的,但是正如预期的那样,JavaScript的更改并不是服务器上的永久性。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<style>
.hide {
display:none;
}
.show {
display:block;
}
</style>
<h3>Schedule this week's appointment!</h3>
<form action="form_test.html" onSubmit="reserveApt()">
<input type="checkbox" id="check1" name="monday"><label for="monday">Monday</label><br>
<input type="checkbox" id="check2" name="tuesday"><label for="tuesday">Tuesday</label><br>
<input type="checkbox" id="check3" name="wednesday"><label for="Wednesday">Wednesday</label><br>
<input type="checkbox" id="check4" name="thursday"><label for="thursday">Thursday</label><br>
<input type="checkbox" id="check5" name="friday"><label for="friday">Friday</label><br><br>
<input type="submit" value="Submit">
</form>
<script>
function reserveApt() {
var input1 = document.getElementById("check1");
var input2 = document.getElementById("check2");
var input3 = document.getElementById("check3");
var input4 = document.getElementById("check4");
var input5 = document.getElementById("check5");
if(input1.checked == true) {
input1.className = "hide";
input1.disabled = true;
}
if(input2.checked == true) {
input2.className = "hide";
input2.disabled = true;
}
if(input3.checked == true) {
input3.className = "hide";
input3.disabled = true;
}
if(input4.checked == true) {
input4.className = "hide";
input4.disabled = true;
}
if(input5.checked == true) {
input5.className = "hide";
input5.disabled = true;
}
}
</script>
</body>
</html>
,尽管可以解决您试图通过方法解决的问题,但这将非常低效。改用持久数据。使用MySQL,Mariadb甚至MongoDB之类的东西,以跟踪已经花了哪些日子。
您可以创建一张桌子,该桌子可以保留该公寓的确切MM-DD-yy(月份(。这不仅允许您永久存储预订并查询现有的预订,还可以让您与实际日期联系,因此您可以在与实际日期相关的工作日预订,而不仅仅是一般一天。p>这里有一些链接,可以使用PHP(最著名的PHP数据库(开始MySQL。
https://www.w3schools.com/php/php_mysql_intro.asphttps://www.tutorialspoint.com/php/php_and_mysql.htm
您可能需要在本地计算机上安装MySQL。
尝试提供PHP-MYSQL生态系统的捆绑二进制文件。
仅Windows(和Mariadb(:https://www.apachefriends.org/index.html
Windows和Mac:https://www.mamp.info/en/
我希望这会有所帮助!
欢呼!