精彩瞬间
javascript
// 脚本// 根据 JSON 数据填充球队和比分
function updateMatches(data) {const matchesTable = document.getElementById("matches");const highlightsList = document.getElementById("highlights");// 清空表和列表matchesTable.innerHTML = "";highlightsList.innerHTML = "";// 遍历数据data.forEach(match => {// 创建新行const row = document.createElement("tr");// 创建单元格const leagueCell = document.createElement("td");const homeTeamCell = document.createElement("td");const awayTeamCell = document.createElement("td");const scoreCell = document.createElement("td");const timeCell = document.createElement("td");// 填充单元格内容leagueCell.textContent = match.league;homeTeamCell.textContent = match.homeTeam;awayTeamCell.textContent = match.awayTeam;scoreCell.textContent = `${match.homeScore} - ${match.awayScore}`;timeCell.textContent = match.time;// 将单元格添加到行中row.appendChild(leagueCell);
Team' => $row['home_team'],'awayTeam' => $row['away_team'],'homeScore' => $row['home_score'],'awayScore' => $row['away_score'],'time' => $row['time'],'highlight' => $highlight);
}// 返回 JSON 数据
header('Content-Type: application/json');
echo json_encode($matches);// 关闭数据库连接
$conn->close();