助教天團
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Help
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
--- tags: 30 天軟體工程師體驗營|2025 --- > 建議觀看的影音章節: > JS - DOM > # 🏅 JS 任務 Day20 - innerHTML 請同學依照下方觀念練習,並回答問題。 1. 透過 innerHTML 可以取得 DOM 元素內的「HTML 內容」 HTML: ```htmlembedded= <div class="targetClass"> <!-- 註解、換行、空白也包含在內 --> <p>HTML 標籤的內容也被選取</p> </div> ``` JS: ```javascript= const targetClass = document.querySelector(".targetClass"); console.log(targetClass.innerHTML); ``` 結果(以下為 Chrome console 的顯示結果): ![](https://i.imgur.com/Kn10GjQ.png) 2. 可以透過 innerHTML 替換 DOM 元素內的 HTML,需要注意以下幾個重點: - 原先的所有內容都會被清空 - 新的內容將被瀏覽器解析成「HTML」,也就是說會保留 HTML 標籤的特性。 HTML: ```htmlembedded= <!-- 以下的 p 標籤會被清空 --> <div class="targetClass"> <p>替換這個 p 標籤</p> </div> ``` JS: ```javascript= const targetClass = document.querySelector(".targetClass"); targetClass.innerHTML = "<h3>修改後的內容</h3>"; ``` 結果: (網頁渲染出的畫面) ![](https://i.imgur.com/jlK0C6J.png) (修改後的 HTML 結構) ![](https://i.imgur.com/2ilR3vL.png) 3. innerHTML 可以跟變數混合使用 HTML: ```htmlembedded= <div class="targetClass"></div> ``` JS: ```javascript= const targetClass = document.querySelector(".targetClass"); let score = 100; targetClass.innerHTML = `<p>小華的成績為 ${score} 分</p>` ``` 結果: (網頁渲染出的畫面) ![](https://i.imgur.com/Qz857qD.png) (修改後的 HTML 結構) ![](https://i.imgur.com/El6951M.png) 問題 --- 1. 請練習用 querySelector 取得以下 HTML 程式碼中的元素(`.list`),並運用 innerHTML 使其可以呈現出下方圖片的結構 ![](https://i.imgur.com/zDJ7Ps2.png) HTML: ```htmlembedded= <ul class="list"> <li>...</li> </ul> ``` 2. 根據下方 HTML 程式碼,若想使用 JS 在其新增一個使用 h1 標籤包覆,文字內容為「標題」的結構該如何撰寫,請在下方選項中選出可以正確呈現的程式碼 HTML: ```htmlembedded= <div class="title"></div> ``` 選項: ``` 1. document.querySelector(".title").textContent = `<h1>標題</h1>`; 2. document.querySelector(".title").textContent = `標題`; 3. document.querySelector(".title").innerHTML = `<h1>標題</h1>`; ``` ## 回報流程 1. 將答案貼在 Codepen 並複製 Codepen 連結貼至「回報區」回報 (也可以將答案直接貼至「回報區」) ![](https://i.imgur.com/vftL5i0.png) <!-- 解答: 1. ```javascript= const list = document.querySelector(".list"); list.innerHTML = `<li>1</li><li>2</li><li>3</li>`; ``` 2. 3 --> 回報區 --- | 報數 | Discord 名字 | Codepen/其他回饋 | |:----:|:-------------------:|:---------------------------------------------------------------------------------------------------------------------------------:| | 1 | dean | [Codepen](https://codepen.io/ch933114/pen/ogXvbKV?editors=1010) | |2| Saika| [Codepen](https://codepen.io/saika4501/pen/XJbrdXB?editors=1111)| |3| jingle0900| [Codepen](https://codepen.io/EvaLi0472/pen/azOoNjg)| | 4 | 4chan | [Codepen](https://codepen.io/ijuolaqc-the-looper/pen/VYLZjKp) | | 5 | ying | [Codepen](https://codepen.io/Lara-Lin/pen/jEPNrBd) | | 6 | pastor | [Codepen](https://codepen.io/peter_hung/pen/LEVPZEN) | | 7 | RUDY | [Codepen](https://codepen.io/Rudy-crw/pen/zxGOZON?editors=1011) | | 8 | Hugh | [Codepen](https://codepen.io/Hugh-Chen/pen/gbpYmvN?editors=1111) | | 9 | B | [Codepen](https://codepen.io/Babel777/pen/dPobNaZ) | | 10 | 力文 | [Codepen](https://codepen.io/liwenchiou/pen/OPVLgVz?editors=1010) | |11|JHT| [Codepen](https://codepen.io/juanht/pen/raVBzjy?editors=1111) | | 12 | 7Lun | [Day20-Codepen](https://codepen.io/mfyvqhsn-the-bold/pen/zxGOPXK) | | 13 | nora_zizi | [Codepen](https://codepen.io/Nora-Ch/pen/ogXvExO) | | 14 | HawkeyeLin |[Codepen](https://codepen.io/long-long/pen/gbpYeWo)| | 15 | oyll | [Codepen](https://codepen.io/dizzydog-rgb/pen/zxGOjvN) | | 16 | WEIWEI | [Codepen](https://codepen.io/weiwei93/pen/ZYGzQVX) | | 17 | kelsonhouse|[Codepen](https://codepen.io/Kelson-House/pen/qEdWKjw?editors=0011)| |18|蛋殼|[Codepen](https://codepen.io/weybrian/pen/NPqKzmX) | 19 | Ariel | [Codepen](https://codepen.io/ariel0510/pen/PwqYdox?editors=1010) | 20 | Leonard | [Codepen](https://codepen.io/hyyfjqra-the-sans/pen/xbGKaYY) | 21 | Chuang | [Codepen](https://codepen.io/uidoytjq-the-solid/pen/yyNLdXR?editors=1011) | |22|小趴|[Codepen](https://codepen.io/papa2415/pen/xxNOWaR)| | 23 | wei_0982 | [Codepen](https://codepen.io/nico-lai/pen/RNPNKMK) | | 24 | mercury2508. | [Codepen](https://codepen.io/Mercury2508/pen/ByNLaNO) | | 25 | xiaocai_97765 | [Codepen](https://codepen.io/dupre55667788/pen/azOpKzY) | 26 | ninii | [Codepen](https://codepen.io/niiniiii/pen/QwbvBGg) | 27 | William Hsieh | [Codepen](https://codepen.io/lsaimqxa-the-vuer/pen/ZYGyWKO?editors=1011) | | 28 | Jessie_Yu | [Jessie_Yu 的 Codepen](https://codepen.io/bakyfkso-the-looper/pen/YPXryeB?editors=1111)| | 29 | 叮咚 | [Codepen](https://codepen.io/pinchieh-lin/pen/ByoygWO)| <!-- | num | user | [Codepen]() | -->

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

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.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully