欢迎使用我们的足球比分实时更新服务。在这里,您可以秒速了解最新的进球和比分变化。
正在进行的比赛
已结束的比赛
<script>
// WebSocket 客户端var websocket = new WebSocket("ws://localhost:8080");// 打开 WebSocket 连接时触发websocket.onopen = function() {console.log("WebSocket 连接已打开");};// 收到 WebSocket 消息时触发websocket.onmessage = function(event) {// 解析 JSON 数据var data = JSON.parse(event.data);// 更新正在进行的比赛数据if (data.type === "live") {var matchRow = document.getElementById("match-" + data.matchId);if (matchRow) {matchRow.getElementsByTagName("td")[3].innerHTML = data.score;} else {matchRow = document.createElement("tr");matchRow.id = "match-" + data.matchId;matchRow.innerHTML = "
" + data.matchTime + " | " + data.homeTeam + " | " + data.awayTeam + " | " + data.score + " | ";document.getElementById("live-matches").appendChild(matchRow);}}// 更新已结束的比赛数据else if (data.type === "finished") {var matchRow = document.getElementById("match-" + data.matchId);if (matchRow) {matchRow.getElementsByTagName("td")[3].innerHTML = data.score;} else {matchRow = document.createElement("tr");matchRow.id = "match-" + data.matchId;matchRow.innerHTML = "
" + data.matchTime + " | " + data.homeTeam + " | " + data.awayTeam + " | " + data.score + " | ";document.getElementById("finished-matches").appendChild(matchRow);}}};// WebSocket 连接发生错误时触发websocket.onerror = function(error) {console.log("WebSocket 连接发生错误:" + error);};// WebSocket 连接关闭时触发websocket.onclose = function() {console.log("WebSocket 连接已关闭");};
</script>
相关阅读: 足球比分实时更新 秒速知晓进球和比分变化