
<style>
body {font-family: Arial, sans-serif;font-size: 14px;line-height: 1.5em;}h1 {font-size: 24px;margin-bottom: 10px;}h2 {font-size: 18px;margin-bottom: 10px;}table {border-collapse: collapse;width: 100%;}th, td {border: 1px solid 000;padding: 5px;}.live {background-color: 00ff00;}.finished {background-color: 8) {var response = JSON.parse(xhr.responseText);var liveMatchesTable = document.getElementById("live-matches");var liveMatchesBody = liveMatchesTable.getElementsByTagName("tbody")[0];// 清空現有數據while (liveMatchesBody.hasChildNodes()) {liveMatchesBody.removeChild(liveMatchesBody.lastChild);}// 添加新數據for (var i = 0; i < response.length; i++) {var match = response[i];var row = liveMatchesBody.insertRow(-1);var homeTeamCell = row.insertCell(0);homeTeamCell.innerHTML = match.homeTeam;var awayTeamCell = row.insertCell(1);awayTeamCell.innerHTML = match.awayTeam;var scoreCell = row.insertCell(2);scoreCell.innerHTML = match.score;var timeCell = row.insertCell(3);timeCell.innerHTML = match.time;var analysisCell = row.insertCell(4);analysisCell.innerHTML = match.analysis;}}};xhr.open("GET", "live-matches.php", true);xhr.send();}// 使用AJAX獲取已結束比賽信息function getFinishedMatches() {var xhr= new XMLHttpRequest();xhr.onreadystatechange = function() {if (xhr.readyState === 4 && xhr.status === 200) {var response = JSON.parse(xhr.responseText);var finishedMatchesTable = document.getElementById("finished-matches");var finishedMatchesBody = finishedMatchesTable.getElementsByTagName("tbody")[0];// 清空現有數據while (finishedMatchesBody.hasChildNodes()) {finishedMatchesBody.removeChild(finishedMatchesBody.lastChild);}// 添加新數據for (var i = 0; i < response.length; i++) {var match = response[i];var row = finishedMatchesBody.insertRow(-1);var homeTeamCell = row.insertCell(0);homeTeamCell.innerHTML = match.homeTeam;var awayTeamCell = row.insertCell(1);awayTeamCell.innerHTML = match.awayTeam;var scoreCell = row.insertCell(2);scoreCell.innerHTML = match.score;var timeCell = row.insertCell(3);timeCell.innerHTML = match.time;var analysisCell = row.insertCell(4);analysisCell.innerHTML = match.analysis;}}};xhr.open("GET", "finished-matches.php", true);xhr.send();}// 定時刷新實時比賽信息setInterval(getLiveMatches, 1000);// 定時刷新已結束比賽信息setInterval(getFinishedMatches, 60000);</script>