<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>
鄭重聲明:本文由:
民宿酒店新聞于(2024-09-28)發(fā)表了關(guān)于
成都住宿多少一晚 (成都住宿多少錢一晚)的文章。如轉(zhuǎn)載請注明出處!部分文章來源于網(wǎng)絡(luò),僅作為參考,如果網(wǎng)站中圖片和文字侵犯了您的版權(quán),請聯(lián)系我們處理!