<script> const matchesContainer = document.getElementById("matches");// 模擬獲取實時比賽數(shù)據(jù)const getMatches = () => {const matches = [{id: 1,teams: ["中國", "日本"],status: "進行中",score: {home: 1,away: 0}},{id: 2,teams: ["巴西", "阿根廷"],status: "未開始",score: null},{id: 3,teams: ["法國", "德國"],status: "已結束",score: {home: 2,away: 1}}];return matches;};// 渲染比賽數(shù)據(jù)const renderMatches = (matches) => {matches.forEach(match => {const matchElement = createMatchElement(match);matchesContainer.appendChild(matchElement);});};// 創(chuàng)建比賽元素const createMatchElement = (match) => {const matchElement = document.createElement("div");matchElement.classList.add("match");const matchHeader = createMatchHeader(match);matchElement.appendChild(matchHeader);const matchDetails = createMatchDetails(match);matchElement.appendChild(matchDetails);return matchElement;};// 創(chuàng)建比賽頭部信息const createMatchHeader = (match) => {const matchHeader = document.createElement("div");matchHeader.classList.add("match-header");const matchTeams = createMatchTeams(match);matchHeader.appendChild(matchTeams);const matchStatus = createMatchStatus(match);matchHeader.appendChild(matchStatus);return matchHeader;};// 創(chuàng)建比賽球隊信息const createMatchTeams = (match) => {const matchTeams = document.createElement("div");matchTeams.classList.add("match-teams");const homeTeam = createMatchTeam(match.teams[0]);matchTeams.appendChild(homeTeam);const awayTeam = createMatchTeam(match.teams[1]); matchTeams.appendChild(awayTeam);return matchTeams;};// 創(chuàng)建比賽球隊名稱const createMatchTeam = (teamName) => {const matchTeam = document.createElement("span");matchTeam.classList.add("match-team");matchTeam.textContent = teamName;return matchTeam;};// 創(chuàng)建比賽狀態(tài)信息const createMatchStatus = (match) => {const matchStatus = document.createElement("span");matchStatus.classList.add("match-status");matchStatus.textContent = match.status;return matchStatus;};// 創(chuàng)建比賽詳情信息const createMatchDetails = (match) => {const matchDetails = document.createElement("div");matchDetails.classList.add("match-details");if (match.status === "進行中") {const matchScore = createMatchScore(match.score);matchDetails.appendChild(matchScore);}return matchDetails;};// 創(chuàng)建比賽比分信息const createMatchScore = (score) => {const matchScore = document.createElement("span");matchScore.classList.add("match-score");matchScore.textContent = `${score.home} - ${score.away}`;return matchScore;};const matches = getMatches();renderMatches(matches); </script>