<script>
const form = document.getElementById('form');form.addEventListener('submit', (e) => {e.preventDefault();const query = e.target.querySelector('input[name="query"]').value;// 調用你的 API 獲取比賽結果并顯示在 results 容器中// 例如:fetch(`${query}`).then(response => response.json()).then(data => {const resultsContainer = document.getElementById('results');// 創建表格顯示比賽結果const table = document.createElement('table');table.classList.add('results-table');// 創建表頭const headerRow = document.createElement('tr');const headerCells = ['比賽名稱', '開始時間', '主隊', '客隊', '比分'];headerCells.forEach(cell => {const th = document.createElement('th');th.textContent = cell;headerRow.appendChild(th);});table.appendChild(headerRow);// 創建表格主體data.matches.forEach(match => {const row = document.createElement('tr');const nameCell = document.createElement('td');nameCell.textContent = match.name;row.appendChild(nameCell);const startTimeCell = document.createElement('td');startTimeCell.textContent = match.startTime;row.appendChild(startTimeCell);const homeTeamCell = document.createElement('td');homeTeamCell.textContent = match.homeTeam;row.appendChild(homeTeamCell);const awayTeamCell = document.createElement('td');awayTeamCell.textContent = match.awayTeam;row.appendChild(awayTeamCell);const scoreCell = document.createElement('td');scoreCell.textContent = match.score;row.appendChild(scoreCell);table.appendChild(row);});resultsContainer.appendChild(table);
}).catch(error => {console.error(error);alert('查詢失敗,請稍后重試。');});});
</script>