掌握球場動態(tài)!足球比分直播:即時更新,精彩不斷
來源:24直播網(wǎng)
<style>
body {font-family: Arial, Helvetica, sans-serif;margin: 0;padding:0;}.container {width: 100%;max-width: 1200px;margin: 0 auto;padding: 15px;}.heading {font-size: 36px;font-weight: bold;text-align: center;}.table-container {width: 100%;border-collapse: collapse;border: 1px solid ccc;}heading">比賽 | 主隊 | 比分 | 客隊 | 狀態(tài) | 更新時間 | <script>// 定時器,每5秒獲取一次最新比分const intervalId = setInterval(() => {fetch('https://api.example.com/football-scores').then(response => response.json()).then(data => {// 清除之前的比分信息document.querySelector('live-scores').innerHTML = '';// 遍歷比分數(shù)據(jù)data.forEach(score => {// 創(chuàng)建表格行const row = document.createElement('tr');// 添加比賽信息const match = document.createElement('td');match.classList.add('table-data-left');match.innerHTML = `${score.homeTeam} vs ${score.awayTeam}`;// 添加主隊比分const homeScore = document.createElement('td');homeScore.classList.add('table-data');homeScore.innerHTML = score.homeScore;// 添加比分const scoreCell = document.createElement('td');scoreCell.classList.add('table-data');scoreCell.innerHTML = `${score.homeScore} : ${score.awayScore}`;// 添加客隊比分const awayScore = document.createElement('td');awayScore.classList.add('table-data');awayScore.innerHTML = score.awayScore;// 添加比賽狀態(tài)const status = document.createElement('td');status.classList.add('table-data');status.innerHTML = score.status;// 添加更新時間const updateTime = document.createElement('td');updateTime.classList.add('table-data-right');updateTime.innerHTML = score.updatedAt;// 將單元格添加到表格行row.appendChild(match);row.appendChild(homeScore);row.appendChild(scoreCell);row.appendChild(awayScore);row.appendChild(status);row.appendChild(updateTime);// 顯示比分更新document.querySelector('live-scores').appendChild(row);});}).catch(error => {console.error('Error fetching football scores:', error);alert('無法獲取實時比分,請稍后再試。');});}, 5000);// 當頁面關閉時清除定時器window.addEventListener('beforeunload', () => {clearInterval(intervalId);});</script>