歡迎來到足球比賽即時比分中心。在這里,您可以第一時間獲悉賽場勝負(fù)。
<script>
// 使用 WebSocket 訂閱實時比分?jǐn)?shù)據(jù)const ws = new WebSocket("ws://localhost:8080");ws.onmessage = function(event) {// 解析收到的數(shù)據(jù)const data = JSON.parse(event.data);// 更新比分?jǐn)?shù)據(jù)const row = document.createElement("tr");const match = document.createElement("td");const time = document.createElement("td");const homeTeam = document.createElement("td");const score = document.createElement("td");const awayTeam = document.createElement("td");match.innerText = data.match;time.innerText = data.time;homeTeam.innerText = data.homeTeam;score.innerText = data.score;awayTeam.innerText = data.awayTeam;row.appendChild(match);row.appendChild(time);row.appendChild(homeTeam);row.appendChild(score);row.appendChild(awayTeam);const tableBody = document.querySelector("tbody");tableBody.appendChild(row);};
</script>