<script> const form = document.getElementById('form');const results = document.getElementById('results');const hotelList = results.querySelector('.hotel-list');form.addEventListener('submit', (e) => {e.preventDefault();const checkin = form.querySelector('input[name="checkin"]').value;const checkout = form.querySelector('input[name="checkout"]').value;const adults = parseInt(form.querySelector('input[name="adults"]').value);const children = parseInt(form.querySelector('input[name="children"]').value);const data = {checkin,checkout,adults,children,};fetch('成都住宿价格api地址', {method: 'POST',headers: {'Content-Type': 'application/json',},body: JSON.stringify(data),}).then(res => res.json()).then(data => {hotelList.innerHTML = '';data.forEach(hotel => {const hotelItem = document.createElement('li');hotelItem.classList.add('hotel-item');const hotelName = document.createElement('span');hotelName.classList.add('hotel-name');hotelName.textContent = hotel.name;const hotelPrice = document.createElement('span');hotelPrice.classList.add('hotel-price');hotelPrice.textContent = `¥${hotel.price}`;hotelItem.appendChild(hotelName);hotelItem.appendChild(hotelPrice);hotelList.appendChild(hotelItem);});}).catch(err => {alert('查询失败,请稍后再试。');console.error(err);});}); script>