JavaScript 必修篇 - 前端修練全攻略
本日對應章節為:todolist 待辦事項、陣列資料操作、箭頭函式基本寫法。
鍵盤事件 keyup 可以拿來偵測是否按下特定鍵盤,而 keyup 的觸發時機為當你按下特定鍵盤又放開的那刻:
<input type="text">
//透過 querySelector 選取 input 欄位
const input = document.querySelector('input');
//註冊監聽 input 欄位的 "keyup" 事件
input.addEventListener("keyup", function (e) {
console.log(e);
});
當我點擊 Enter 鍵觸發該 "keyup" 事件時,可以觀察到 Event 包含:
該 "keyup" Event 內相當多的屬性,如果我們希望點擊到 Enter 時,可以觸發對應事件,可以透過以下方式:
//註冊監聽 input 欄位的 "keyup" 事件
input.addEventListener("keyup", function (e) {
//如果屬性的 key 值為 "Enter"
if (e.key === "Enter") {
//符合條件就執行大括號內程式碼
console.log('我鍵盤按了 Enter ')
}
});
想多了解鍵盤事件怎麼觸發,可以點擊此 CodePen 檔案。
此為最終關卡任務,為了給同學更多實作空間,此次會縮減步驟指引,改以大方向提示的方式唷!
請同學 fork 此 👉 CSS 範本,或使用已實現其他功能之 todoList ,今天要實作刪除全部&優化:
重點提示:
如果真的想不出來卡關了,也不要灰心,這裡有可愛的 Vtuber 艾拉的 👉 todoList 教學 一天實作一點小功能,很快就完成囉!ヽ(✿゚▽゚)ノ
今天的範例投稿有兩份唷,在寫 Code 時,其實沒有所謂的標準解答,卡關時可以參考別人的程式碼,並融會貫通出自己的寫法唷!
將答案寫在 CodePen 複製 CodePen 連結貼至下方作業投稿區中回報就算完成了喔!
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing