全美橄榄球联盟比分看板:即时更新,精彩不断
发布时间:2024-07-20 03:55:56【足球快讯】人次阅读
摘要即时更新,精彩不断时间主队比分客队状态,定时刷新比分数据setInterval,function,通过AJAX获取最新比分数据varxhr=newXMLHttpRequest,xhr.open,GET,get,scores.php,xhr.onload=function,if,xhr.status===200,...。
即时更新,精彩不断
<script>
// 定时刷新比分数据setInterval(function() {// 通过 AJAX 获取最新比分数据var xhr = new XMLHttpRequest();xhr.open("GET", "get_scores.php");xhr.onload = function() {if (xhr.status === 200) {// 解析比分数据var scores = JSON.parse(xhr.responseText);// 更新比分看板var tbody = document.querySelector("tbody");tbody.innerHTML = "";for (var i = 0; i < scores.length; i++) {var score = scores[i];var tr = document.createElement("tr");tr.innerHTML =`
${score.time} | ${score.home_team} | ${score.score_home} - ${score.score_away} | ${score.away_team} | ${score.status} | `;tbody.appendChild(tr);}}};xhr.send();}, 5000);// 比赛状态高亮显示var rows = document.querySelectorAll("tbody tr");for (var i = 0; i < rows.length; i++) {var row = rows[i];var status = row.querySelector("td:last-child").textContent;if (status === "完赛") {row.classList.add("highlight");}}
</script>
标签: 精彩不断全美橄榄球联盟比分看板即时更新
很赞哦! ()