嗨嗨大家,歡迎來到coding小白盜版學校官網的第27天~這個計畫的內容是我這個coding超新手會在這30天裡,把複刻學校官網當作目標,從最基礎的前端html、css、js...開始邊做邊學,紀錄每天的學習進度,看看一個月過去能學到什麼程度。今天的新進度是~~
畢竟現在沒有資料庫只是單純的前端,所以只是做個長得很像的功能,在搜尋欄輸入關鍵字可以連到外部網頁
這個功能做起來很簡單(畢竟是chatgpt寫ㄉ),總之就是只要在js加入這段
//搜尋功能
document.getElementById("search").addEventListener("keypress", function(e) {
if (e.key === "Enter") { // 按下 Enter 鍵
const keyword = e.target.value.trim().toLowerCase(); // 使用者輸入內容
// 根據關鍵字跳轉外部網站
if (keyword === "俄羅斯方塊") {
window.location.href = "https://github.tanchangwen.com/react-tetris/";
} else if (keyword === "youtube") {
window.location.href = "https://www.youtube.com";
} else if (keyword === "github") {
window.location.href = "https://github.com";
}
}
});
然後在html裡的input標籤加上id=”search”
<div for="search">
<button class="bt01"><img class="img02" src="img\icon_search.png" alt="搜尋"></button>
<input class="text-box" id="search" type="text" placeholder="關鍵字">
</div>
就輕輕鬆鬆完成啦~~
哼哼是的,或許你有發現,我偷渡了點好東西
之前有一段時間很沉迷,好久沒玩了久違的玩一局吧
果然用電腦鍵盤玩起來就是比手機有fu,有點生疏一下就game over了
今天進度就這樣嘍,明天見啦ㄅㄅ~~