You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.8 KiB

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>星座和生肖查询</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0;
padding: 20px;
background-color: #f4f4f4;
}
.container {
max-width: 600px;
margin: auto;
padding: 20px;
background-color: white;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
h1 {
color: #333;
text-align: center;
}
form {
display: flex;
flex-direction: column;
}
label {
margin-bottom: 5px;
}
input[type="date"] {
padding: 8px;
margin-bottom: 20px;
border: 1px solid #ddd;
border-radius: 4px;
}
button {
padding: 10px;
background-color: #5c6bc0;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #3f51b5;
}
#result {
margin-top: 20px;
padding: 10px;
background-color: #e8eaf6;
border-radius: 4px;
}
</style>
</head>
<body>
<div class="container">
<h1>星座和生肖查询</h1>
<form id="zodiacForm">
<label for="birthdate">请输入您的出生日期:</label>
<input type="date" id="birthdate" required>
<button type="submit">查询星座和生肖</button>
</form>
<div id="result"></div>
</div>
<script>
document.getElementById('zodiacForm').addEventListener('submit', function(e) {
e.preventDefault();
const birthdate = document.getElementById('birthdate').value;
fetch('zodiac.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: 'birthdate=' + birthdate
})
.then(response => response.json())
.then(data => {
document.getElementById('result').innerHTML = `
<h2>查询结果:</h2>
<p>西方星座:${data.westernZodiac}</p>
<p>中国生肖:${data.chineseZodiac}</p>
`;
})
.catch(error => {
console.error('Error:', error);
document.getElementById('result').innerHTML = '发生错误,请重试。';
});
});
</script>
</body>
</html>