查找附近维修店 (查找附近维修钟表店)

成都夜店 04-16 阅读:53 评论:0

搜索结果:

javascript // script.jsconst results = document.getElementById('results');document.addEventListener('DOMContentLoaded', () => {// 注册搜索表单提交事件监听器document.querySelector('form').addEventListener('submit', (e) => {e.preventDefault();// 获取搜索字段和类别字段的值const location = document.getElementById('location').value;const category = document.getElementById('category').value;// 构建 API 查询 URLconst url = `${location}&category=${category}`;// 使用 fetch API 发出请求fetch(url).then((response) => response.json()).then((data) => {// 清除以前的搜索结果results.innerHTML = '';// 遍历搜索结果data.results.forEach((result) => {// 创建一个列表项const li = document.createElement('li');// 创建一个标题元素const title = document.createElement('h3');title.textContent = result.name;// 创建一个地址元素const address = document.createElement('p');address.textContent = result.address;// 创建一个电话号码元素const phone = document.createElement('p');phone.textContent = result.phone;// 将元素添加到列表项li.appendChild(title);li.appendChild(address);li.appendChild(phone);// 将列表项添加到搜索结果列表中results.appendChild(li);});}).catch((error) => {console.error('Error fetching data:', error);});}); });
版权声明

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