欢迎来到在线修车咨询平台!在这里,您可以获得来自专业汽车技师的免费咨询服务。无论您遇到任何汽车问题,都可以通过我们的平台轻松便捷地获得帮助。
CSS 代码:
css
body {font-family: Arial, Helvetica, sans-serif;
}.container {max-width: 600px;margin: 0 auto;
}h1 {font-size: 24px;margin-bottom: 20px;
}p {font-size: 16px;margin-bottom: 20px;
}form {display: flex;flex-direction: column;gap: 20px;
}input,
select,
textarea {width: 100%;padding: 10px;border: 1px solid ccc;
}textarea {height: 100px;
}button {width: 100%;background-color: 007bff;color: fff;padding: 10px;border: none;cursor: pointer;
}result {background-color: f5f5f5;padding: 10px;margin-top: 20px;
}JavaScript 代码:
javascript
const carMakeElement = document.getElementById('car_make');
const carModelElement = document.getElementById('car_model');carMakeElement.addEventListener('change', (event) => {const make = event.target.value;const models = getCarModels(make);carModelElement.innerHTML = '';models.forEach((model) => {const option = document.createElement('option');option.value = model;option.textContent = model;carModelElement.appendChild(option);});
});const getCarModels = (make) => {const models = {丰田: ['卡罗拉', '凯美瑞', '雷克萨斯'],本田: ['思域', '雅阁', '奥德赛'],日产: ['轩逸', '天籁', '奇骏'],大众: ['高尔夫', '帕萨特', '途观'],福特: ['福克斯', '蒙迪欧', '锐界'],};return models[make] || [];
};const submitForm = (event) => {event.preventDefault();const formData = new FormData(event.target);constdata = Object.fromEntries(formData.entries());fetch('submit.php', {method: 'POST',headers: {'Content-Type': 'application/json',},body: JSON.stringify(data),}).then((response) => response.json()).then((data) => {document.getElementById('result').innerHTML = data.message;}).catch((error) => {document.getElementById('result').innerHTML = '提交失败!请重试。';});
};const form = document.querySelector('form');
form.addEventListener('submit', submitForm);