<script>
var array = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
<?php
$seatsArray = array();
$myFile = fopen("seats.txt", "w") or die("Unable to Open File!");
if(filesize("seats.txt") == 0) {
for($x = 0; $x < 10; $x++) {
fwrite($myFile, "0\n");
}
}
$seatsArray = file("seats.txt", FILE_IGNORE_NEW_LINES);
fclose($myFile);
print_r($seatsArray);
?>
function checkNumber() {
var number = document.getElementById("userInput").value;
if(number == 1) {
firstClass();
}
else if(number == 2) {
economyClass();
}
else {
document.getElementById("message").innerHTML = "Please enter either 1 or 2.";
}
}
function firstClass() {
for(var x = 0; x <= 4; x++) {
if(array[x] == 0) {
array[x] = 1;
document.getElementById("message").innerHTML = "You have been assigned seat #" + (x+1) + " in first class.";
document.getElementById("f" + (x+1)).style.color = "red";
document.getElementById("userInput").value = "";
break;
}
else if(array[4] == 1) {
document.getElementById("frow").style.color = "red";
if(array[9] == 1) {
document.getElementById("message").innerHTML = "Sorry, the flight is fully booked. The next flight is in three hours.";
}
else {
var confirmation = window.confirm("First class is fully booked, would you like a seat in economy?");
if(confirmation) {
economyClass();
break;
}
else {
document.getElementById("message").innerHTML = "The next flight is in three hours.";
break;
}
}
}
}
}
function economyClass() {
//ETC ETC
</script>
我想將數組移動到一個文本文件,以便在關閉後保留它的值,但只要我將PHP代碼添加到所有其他功能停止工作。 PHP代碼本身起作用,創建座位文件並填充它,但之後的所有內容都沒有。將PHP添加到腳本會導致其餘的JS函數停止工作
學校
哎,完全忘了這條線,我用它早在體內,以檢查是否它正在工作。我評論說,現在一切都重新開始。謝謝。 (儘快選擇答案) –