没有合适的资源?快使用搜索试试~ 我知道了~
JavaScript 全栈教程[廖雪峰 ].CHM

温馨提示
JavaScript 全栈教程[廖雪峰 ].CHM
资源推荐
资源评论




格式:x-rar 资源大小:188.6KB








格式:txt 资源大小:116.0B 页数:1


















<script>
// 搜索引擎配置
const engines = {{
baidu: "https://www.baidu.com/s?wd=",
google: "https://www.google.com/search?q=",
bing: "https://www.bing.com/search?q=",
ai: "https://www.baidu.com/s?wd=AI+" // AI搜索前缀
}};
let currentEngine = "baidu";
const HISTORY_KEY = "searchHistory";
// DOM元素
const searchInput = document.getElementById("searchInput");
const searchBtn = document.getElementById("searchBtn");
const engineBtns = document.querySelectorAll(".engine-btn");
const hotTagsContainer = document.getElementById("hotTagsContainer");
const refreshHotBtn = document.getElementById("refreshHot");
const historyList = document.getElementById("historyList");
const clearHistoryBtn = document.getElementById("clearHistory");
const allHotSearches = JSON.parse(document.getElementById("allHotSearches").textContent);
// 初始化页面
document.addEventListener("DOMContentLoaded", () => {{
loadSearchHistory();
updateSearchButton();
// 设置引擎按钮事件
engineBtns.forEach(btn => {{
btn.addEventListener("click", () => {{
engineBtns.forEach(b => b.classList.remove("active"));
btn.classList.add("active");
currentEngine = btn.dataset.engine;
updateSearchButton();
}});
}});
// 搜索按钮事件
searchBtn.addEventListener("click", performSearch);
// 回车键搜索
searchInput.addEventListener("keyup", (e) => {{
if (e.key === "Enter") {{
performSearch();
}}
}});
// 换一换按钮事件
refreshHotBtn.addEventListener("click", refreshHotSearches);
// 清除历史按钮事件
clearHistoryBtn.addEventListener("click", clearSearchHistory);
// 聚焦搜索框
searchInput.focus();
}});
// 更新搜索按钮文字
function updateSearchButton() {{
const engineNames = {{
baidu: "百度一下",
google: "Google搜索",
bing: "必应搜索",
ai: "AI搜索"
}};
searchBtn.textContent = engineNames[currentEngine];
}}
// 执行搜索
function performSearch() {{
const keyword = searchInput.value.trim();
if (!keyword) {{
searchInput.focus();
return;
}}
// 保存搜索历史
saveSearchHistory(keyword);
// 构建搜索URL
let searchUrl = engines[currentEngine] + encodeURIComponent(keyword);
// 特殊处理AI搜索
if (currentEngine === "ai") {{
searchUrl += "&t=ai";
}}
// 打开新标签页
window.open(searchUrl, "_blank");
}}
// 刷新热搜词
function refreshHotSearches() {{
// 随机选择10个不重复的热搜词
const shuffled = [...allHotSearches].sort(() => 0.5 - Math.random());
const selected = shuffled.slice(0, 10);
// 清空容器
hotTagsContainer.innerHTML = '';
// 添加新的热搜标签
selected.forEach((tag, index) => {{
const tagClass = index < 3 ? "" : index < 6 ? "hot" : "new";
const tagElement = document.createElement('div');
tagElement.className = `hot-tag ${{tagClass}}`;
tagElement.dataset.keyword = tag;
tagElement.textContent = tag;
// 添加点击事件
tagElement.addEventListener('click', () => {{
searchInput.value = tag;
performSearch();
}});
hotTagsContainer.appendChild(tagElement);
}});
// 添加轻微动画效果
hotTagsContainer.style.opacity = '0';
setTimeout(() => {{
hotTagsContainer.style.transition = 'opacity 0.3s ease-in-out';
hotTagsContainer.style.opacity = '1';
}}, 10);
}}
// 保存搜索历史
function saveSearchHistory(keyword) {{
let history = JSON.parse(localStorage.getItem(HISTORY_KEY) || '[]');
// 移除重复项
history = history.filter(item => item.keyword !== keyword);
// 添加新记录
history.unshift({{
keyword: keyword,
timestamp: new Date().toISOString()
}});
// 最多保留10条记录
if (history.length > 10) {{
history = history.slice(0, 10);
}}
localStorage.setItem(HISTORY_KEY, JSON.stringify(history));
loadSearchHistory();
}}
// 加载搜索历史
function loadSearchHistory() {{
const history = JSON.parse(localStorage.getItem(HISTORY_KEY) || '[]');
historyList.innerHTML = '';
history.forEach(item => {{
const historyItem = document.createElement('div');
historyItem.className = 'history-item';
historyItem.textContent = item.keyword;
historyItem.addEventListener('click', () => {{
searchInput.value = item.keyword;
performSearch();
}});
historyList.appendChild(historyItem);
}});
}}
// 清除搜索历史
function clearSearchHistory() {{
localStorage.removeItem(HISTORY_KEY);
loadSearchHistory();
}}
</script>
</body>
</html>
'''
# 保存为HTML文件
file_path = os.path.abspath('smart_search_engine.html')
with open(file_path, 'w', encoding='utf-8') as f:
f.write(html_content)
# 自动在浏览器中打开
webbrowser.open(f'file://{file_path}')
return f"已生成智能搜索页面: {file_path}"
# 生成并打开页面
if __name__ == "__main__":
result = generate_search_page()
print(result)
去掉搜索历史
浏览:2
资源评论

- 星繁逐追2018-11-28很不错,值得下载
- mastermanager2018-05-09楼上说的对,当工具书查查还是不错的
- 绝版男子2017-09-05当工具书查查啥的还是不错的

参考手册
- 粉丝: 46
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 2025年职业卫生试题与完整答案.docx
- 2025年政工职称考试题库附答案.docx
- 2025年职业健康基础知识考试(100分)与答案.docx
- 2025年中小学教师晋级职称考试试题(附含答案).docx
- 2025年中国移动招聘考试笔试试题综合能力测试卷和答案.docx
- 2025年职业健康基础知识考试(100分)及答案.docx
- 2025年中国移动招聘考试笔试试题综合能力测试卷与答案.docx
- 2025年中国移动在线测评笔试题库(附答案).docx
- 2025年中国移动在线测评笔试题库(含答案).docx
- 2025年中国石油化工集团中石化招聘笔试试题与答案.docx
- 2025年中小学教师高级职称专业水平能力题库和答案.docx
- 2025年中小学防溺水安全知识竞赛题库与答案.docx
- 2025年中国石油化工集团中石化招聘笔试试题及答案.docx
- 2025年中小学防溺水安全知识竞赛题库及答案.docx
- 2025年中小学教师高级职称专业水平能力题库及答案.docx
- A176基于springboot+vue的扶贫众筹网(完整前后端代码+sql脚本+开发文档+全套软件)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
