<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>帝国CMS搜索栏</title>
<style>
.search-form {
display: flex;
align-items: center;
gap: 8px;
padding: 10px;
background: #f5f5f5;
border-radius: 6px;
}
.search-input {
flex: 1;
padding: 8px 12px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 14px;
background: white;
}
.search-select {
padding: 8px 12px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 14px;
min-width: 100px;
background: white;
}
.search-btn {
padding: 8px 16px;
background: #007cba;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
}
.search-btn:hover {
background: #005a87;
}
</style>
</head>
<body>
<form onsubmit="return checkSearchForm()" method="post" name="searchform" action="/e/search/index.php">
<input type="text" name="keyboard" placeholder="输入关键词搜索...">
<select name="tbname" id="tbnameSelect" onchange="updateHiddenFields()">
<option value="" disabled selected>选择栏目</option>
<option value="news">文章</option>
<option value="download">下载</option>
</select>
<button type="submit">搜索</button>
<input type="hidden" value="title" name="show">
<input type="hidden" value="1" id="tempidField" name="tempid">
<input type="hidden" value="news" id="tbnameField" name="tbname">
<input name="mid" value="1" type="hidden">
<input name="dopost" value="search" type="hidden">
</form>
<script>
function updateHiddenFields() {
const selectElement = document.getElementById('tbnameSelect');
const selectedValue = selectElement.value;
const tempidField = document.getElementById('tempidField');
const tbnameField = document.getElementById('tbnameField');
if (selectedValue === 'news') {
tempidField.value = '1';
tbnameField.value = 'news';
} else if (selectedValue === 'download') {
tempidField.value = '4';
tbnameField.value = 'download';
}
}
function checkSearchForm() {
const keyword = document.querySelector('.search-input').value.trim();
const tbname = document.getElementById('tbnameSelect').value;
if (!keyword) {
alert('请输入搜索关键词!');
return false;
}
if (!tbname) {
alert('请选择搜索栏目!');
return false;
}
return true;
}
document.addEventListener('DOMContentLoaded', function() {
updateHiddenFields();
});
</script>
</body>
</html>