长沙公交车实时到站查询233 (长沙公交车实时到站查询)

长沙耍耍 05-30 阅读:41 评论:0

请输入公交车线路和站点名称,即可查询实时到站信息。


style.css css body {font-family: Arial, sans-serif; }h1 {font-size: 24px;margin-bottom: 10px; }p {font-size: 16px;margin-bottom: 10px; }form {margin-bottom: 10px; }label {margin-right: 5px; }input {width: 200px;padding: 5px;margin-right: 5px; }result {background-color: eee;padding: 10px;margin-top: 10px;display: none; }script.js javascript const form = document.querySelector('form'); const result = document.querySelector('result');form.addEventListener('submit', (e) => {e.preventDefault();const line = document.querySelector('input[name="line"]').value;const station = document.querySelector('input[name="station"]').value;if (!line || !station) {alert('请输入公交车线路和站点名称');return;}const url = `query.php?line=${line}&station=${station}`;fetch(url).then(response => response.json()).then(data => {if (data.error) {alert(data.error);return;}let html = ` 长沙公交车实时到站查询233 (长沙公交车实时到站查询)

${line}路 ${station}站

`;html += '
    ';for (const bus of data.buses) {html += `
  • ${bus.name} ${bus.time}分钟后到站
  • `;}html += '
';result.innerHTML = html;result.style.display = 'block';}).catch(error => {console.error(error);alert('查询失败,请稍后再试');}); });query.php php '请输入公交车线路和站点名称']);exit; }// 查询数据库获取公交车实时到站信息 $buses = [['name' => '101路', 'time' => 5],['name' => '102路', 'time' => 10],['name' => '103路', 'time' => 15], ];echo json_encode($buses);
版权声明

本文仅代表作者观点,不代表长沙桑拿立场。
本文系作者授权发表,未经许可,不得转载。