dl / index.html
wuhenba's picture
Create index.html
b1c3672 verified
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>首页</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
font-family: 'Arial', sans-serif;
text-align: center;
background-color: #fff;
color: #333;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
}
.logo img {
width: 270px;
height: auto;
}
.search-box {
margin-top: 30px;
width: 100%;
max-width: 580px;
}
input[type="text"] {
width: 100%;
height: 40px;
padding: 0 13px;
border: 1px solid #e4e4e4;
border-radius: 6px;
font-size: 20px;
box-sizing: border-box;
outline: none;
transition: border-color 0.3s;
}
input[type="text"]:focus {
border-color: #36c;
}
.buttons {
margin-top: 15px;
}
.buttons input[type="submit"] {
width: 100px;
height: 36px;
border: none;
border-radius: 2px;
background-color: #38f;
color: #fff;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s;
}
.buttons input[type="submit"]:hover {
background-color: #5bb8fd;
}
</style>
</head>
<body>
<div class="logo">
<img src="https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png" alt="百度 Logo">
</div>
<div class="search-box">
<form id="inputForm">
<input type="text" id="inputText" value="{{ .site }}">
<div class="buttons">
<input type="submit" value="万能一下">
</div>
</form>
</div>
<script>
document.getElementById('inputForm').addEventListener('submit', function(event) {
event.preventDefault(); // 阻止表单默认提交行为
const inputValue = document.getElementById('inputText').value.trim();
if (inputValue === '') {
alert('请输入内容');
return;
}
// 使用 AJAX 发送数据到后端
fetch('/seturl', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ site: inputValue })
})
.then(response => response.json())
.then(data => {
if (data.msg) {
window.location.href = "/";
} else {
alert('提交失败');
}
// 清空输入框
// document.getElementById('inputText').value = '';
})
.catch(error => {
console.error('Error:', error);
alert('提交失败2: ' + error.message);
});
});
</script>
</body>
</html>