feat: add TypeScript lessons and learning panel

- Introduced a new script to check TypeScript lesson files for errors.
- Created a main TypeScript file to render lessons and their details.
- Added lesson definitions with starter and answer codes.
- Implemented a user interface for navigating and running lessons.
- Styled the application with CSS for a better user experience.
- Updated README to reflect the new TypeScript section and usage instructions.
This commit is contained in:
charlie
2026-03-19 10:06:11 +08:00
parent 69a4ae3178
commit f3bdaa4e88
146 changed files with 5951 additions and 9 deletions

View File

@@ -0,0 +1,25 @@
# 练习 12prepend、classList.remove 和链接默认行为
## 目标
补齐几个常见但容易漏掉的 DOM 细节操作。
## 你要练什么
- `prepend()`
- `classList.remove()`
- 链接点击事件
- `preventDefault()`
## 任务
- 点击“插入到最前面”时,把一条新消息插入列表顶部
- 点击“清除高亮”时,移除全部高亮类名
- 点击帮助链接时,阻止默认跳转,并在页面显示提示信息
## 文件
- [starter.html](/Users/lijiaqing/home/wwwroot/front-end-example/04-dom-events-async/12-prepend-remove-and-link-default/starter.html)
- [starter.js](/Users/lijiaqing/home/wwwroot/front-end-example/04-dom-events-async/12-prepend-remove-and-link-default/starter.js)
- [answer.html](/Users/lijiaqing/home/wwwroot/front-end-example/04-dom-events-async/12-prepend-remove-and-link-default/answer.html)
- [answer.js](/Users/lijiaqing/home/wwwroot/front-end-example/04-dom-events-async/12-prepend-remove-and-link-default/answer.js)

View File

@@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>prepend、classList.remove 和链接默认行为</title>
<style>
body {
margin: 0;
padding: 32px;
font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
background: #f5f7fb;
}
.panel {
max-width: 760px;
margin: 0 auto;
padding: 24px;
border-radius: 18px;
background: #ffffff;
border: 1px solid #dce4ef;
}
.item {
margin-top: 10px;
padding: 12px 14px;
border-radius: 12px;
border: 1px solid #dbe4f0;
}
.item.active {
background: #dbeafe;
}
.actions {
display: flex;
gap: 10px;
flex-wrap: wrap;
}
</style>
</head>
<body>
<section class="panel">
<h1>补漏练习</h1>
<div class="actions">
<button id="prepend-btn" type="button">插入到最前面</button>
<button id="clear-active-btn" type="button">清除高亮</button>
<a id="help-link" href="https://example.com/help">查看帮助</a>
</div>
<p id="hint-text">这里会显示操作提示。</p>
<ul id="message-list">
<li class="item active">先学事件监听</li>
<li class="item active">再学异步顺序</li>
<li class="item">最后做综合页面</li>
</ul>
</section>
<script src="./answer.js"></script>
</body>
</html>

View File

@@ -0,0 +1,31 @@
const prependButton = document.getElementById("prepend-btn");
const clearActiveButton = document.getElementById("clear-active-btn");
const helpLink = document.getElementById("help-link");
const hintText = document.getElementById("hint-text");
const messageList = document.getElementById("message-list");
let messageIndex = 1;
prependButton.addEventListener("click", function () {
const item = document.createElement("li");
item.className = "item active";
item.textContent = `新插入的提醒 ${messageIndex}`;
messageList.prepend(item);
hintText.textContent = "已把一条消息插入到最前面";
messageIndex += 1;
});
clearActiveButton.addEventListener("click", function () {
const items = document.querySelectorAll(".item");
items.forEach(function (item) {
item.classList.remove("active");
});
hintText.textContent = "已移除全部高亮状态";
});
helpLink.addEventListener("click", function (event) {
event.preventDefault();
hintText.textContent = "已阻止默认跳转";
});

View File

@@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>prepend、classList.remove 和链接默认行为</title>
<style>
body {
margin: 0;
padding: 32px;
font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
background: #f5f7fb;
}
.panel {
max-width: 760px;
margin: 0 auto;
padding: 24px;
border-radius: 18px;
background: #ffffff;
border: 1px solid #dce4ef;
}
.item {
margin-top: 10px;
padding: 12px 14px;
border-radius: 12px;
border: 1px solid #dbe4f0;
}
.item.active {
background: #dbeafe;
}
.actions {
display: flex;
gap: 10px;
flex-wrap: wrap;
}
</style>
</head>
<body>
<section class="panel">
<h1>补漏练习</h1>
<div class="actions">
<button id="prepend-btn" type="button">插入到最前面</button>
<button id="clear-active-btn" type="button">清除高亮</button>
<a id="help-link" href="https://example.com/help">查看帮助</a>
</div>
<p id="hint-text">这里会显示操作提示。</p>
<ul id="message-list">
<li class="item active">先学事件监听</li>
<li class="item active">再学异步顺序</li>
<li class="item">最后做综合页面</li>
</ul>
</section>
<script src="./starter.js"></script>
</body>
</html>

View File

@@ -0,0 +1,6 @@
// 任务:
// 1. 获取两个按钮、帮助链接、提示文字和列表
// 2. 点击 prepend-btn 时创建新 li并插入到列表最前面
// 3. 点击 clear-active-btn 时移除所有 item 的 active 类名
// 4. 点击帮助链接时,用 preventDefault() 阻止跳转
// 5. 在提示文字里输出“已阻止默认跳转”