iT邦幫忙

2025 iThome 鐵人賽

DAY 27
0
自我挑戰組

coding小白盜版學校官網ㄉ30天挑戰日記系列 第 27

coding小白盜版學校官網ㄉ30天挑戰日記 輸入關鍵字前往連結

  • 分享至 

  • xImage
  •  

嗨嗨大家,歡迎來到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>

就輕輕鬆鬆完成啦~~

哼哼是的,或許你有發現,我偷渡了點好東西
之前有一段時間很沉迷,好久沒玩了久違的玩一局吧
https://ithelp.ithome.com.tw/upload/images/20251011/20178754CAJtbdEHJc.png
果然用電腦鍵盤玩起來就是比手機有fu,有點生疏一下就game over了
今天進度就這樣嘍,明天見啦ㄅㄅ~~


上一篇
coding小白盜版學校官網ㄉ30天挑戰日記 用git版本更新&終端機改中文ㄉ方法
系列文
coding小白盜版學校官網ㄉ30天挑戰日記27
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言