<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.">一键脚本</title>
</head>
<body>
<!-- 主页 -->
<nav class="bg-white shadow-lg">
<ul id="nav-list" class="list-unstyled">
<li><a href="#" class="text-white hover:text-gray-2">首页</a></li>
<li><a href="#" class="text-white hover:text-gray-2">us</a></li>
<li><a href="#" class="text-white hover:text-gray-2">联系 us</a></li>
<li><a href="#" class="text-white hover:text-gray-2">链接</a></li>
<li><a href="#" class="text-white hover:text-gray-2">产品</a></li>
<li><a href="#" class="text-white hover:text-gray-2">服务</a></li>
<li><a href="#" class="text-white hover:text-gray-2">联系</a></li>
</ul>
</nav>
<!-- 搜索框 -->
<div class="max-w-3xl mx-auto">
<h3 class="text-white mb-4">搜索</h3>
<form>
<input type="text" id="search" class="w-full px-4 py-2 bg-gray-5 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-5">
<button class="bg-blue-5 text-white px-6 py-2 rounded-lg hover:bg-blue-6">
查找
</button>
</form>
</div>
<!-- 其他脚本 -->
<script>
// 生成导航栏脚本
const navList = document.getElementById('nav-list');
const navLinks = document.querySelectorAll('a');
navList.innerHTML = '';
navLinks.forEach(link => {
const linkElement = link.querySelector();
const href = link.dataset href;
linkElement.innerHTML = `Link ${href}`;
});
// 将搜索框保存到 JavaScript 中
const searchInput = document.getElementById('search');
const searchText = '搜索';
searchInput.addEventListener('input', function () {
const searchTerm = this.dataset.value.toLowerCase();
if (searchTerm === searchTerm) {
document.querySelector('.search-btn').style.display = 'none';
document.querySelector('.search-btn').innerHTML = '搜索';
} else {
document.querySelector('.search-btn').innerHTML = '搜索';
document.querySelector('.search-btn').style.display = 'block';
}
});
</script>
</body>
</html>
功能说明:
- 导航栏: 能够生成一个简单的导航栏,支持多条链接。
- 搜索框: 能够自动加载一个搜索框,支持输入搜索内容。
- 脚本脚本: 保存在 JavaScript 文件中,可以自动运行脚本的执行逻辑。
使用说明:
- 生成导航栏:在网页的顶部点击生成链接。
- 生成搜索框:在搜索框的顶部点击生成链接。
- 搜索:输入搜索内容后,搜索框会自动加载。
注意事项:
- 这是一个简单的脚本,可以作为基础模板。
- 需要根据实际需求调整脚本的逻辑。
- 如果需要脚本的 persistence(persistence存储到本地),可以考虑添加保存脚本到本地的脚本脚本语言。
如果你有具体的功能需求,可以告诉我,我可以帮你进一步完善这个脚本!



