本文参考了 清华大学电子系科协软件部2023暑期培训 ,在此表示感谢。
快速上手
目录
HTML 1
CSS 4
JavaScript 6
例子:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| function count(x, time) { return new Promise((resolve, reject) => { setTimeout(() => { console.log(x); resolve(); },time) }); }
async function counter1() { await count(1, 4000); await count(2, 4000); await count(3, 4000); }
async function counter2() { await count(4, 1000); await count(5, 1000); await count(6, 1000); }
counter1(); counter2();
|
使用 nodejs 运行,运行结果:
一些奇妙的例子(这些文件过于古老,我删除了一些不能用的):
https://github.com/dropsong/JS_Examples
ToDoList 项目
一个简单的小项目。
下面先补充一些小知识。内边距、外边距:

html 文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>ToDoList</title> <link rel="stylesheet" href="style.css"> </head> <body> <div class="container"> <h1>ToDoList</h1> <div class="input-container"> <input type="text" placeholder="添加一个任务..." id="task-input"> <button id="add-btn">+</button> </div> <div class="tasks"> <div class="pending-tasks"> <h2>未完成</h2> </div> <div class="completed-tasks"> <h2>已完成</h2> </div> </div> <div class="delbutton"> <button id="delete-btn">删除已完成</button> </div> </div> <script src="simple.js"></script> </body> </html>
|
css 文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
| * { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: Arial, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; background-color: #f4f4f4; }
.container { background-color: white; padding: 20px; border-radius: 10px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); width: 400px; }
h1 { text-align: center; margin-bottom: 20px; }
.input-container { display: flex; justify-content: space-between; margin-bottom: 20px; }
input[type="text"] { width: 80%; padding: 10px; border: 1px solid #ddd; border-radius: 5px; font-size: 16px; }
button { padding: 10px; background-color: orange; border: none; border-radius: 5px; color: white; cursor: pointer; font-size: 16px; }
button:hover { background-color: darkorange; }
.tasks { display: flex; justify-content: space-between; }
.pending-tasks, .completed-tasks { width: 48%; padding: 10px; border-radius: 5px; box-shadow: 0 0 5px rgba(0, 0, 0, 0.1); }
.pending-tasks { background-color: #ff726f; }
.completed-tasks { background-color: #79e376; }
h2 { text-align: center; color: white; }
.delbutton { display: flex; justify-content: space-between; margin-top: 20px; }
.delbutton button { width: 100%; background-color: #ddd; }
.delbutton button:hover { background-color: #ccc; }
.pending-tasks li span, .completed-tasks li span { font-size: 20px; color: white; margin-left: 10px; }
.pending-tasks li input[type="checkbox"], .completed-tasks li input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }
.completed-tasks li span { text-decoration: line-through; color: #888; }
|
js 文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| const taskInput = document.getElementById("task-input"); const addTaskBtn = document.getElementById("add-btn"); const incompleteTasks = document.querySelector(".pending-tasks"); const completedTasks = document.querySelector(".completed-tasks"); const clearCompletedBtn = document.getElementById("delete-btn");
addTaskBtn.addEventListener("click", function() { const taskText = taskInput.value;
if (taskText.trim() === "") { alert("请输入任务内容"); return; }
const li = document.createElement("li");
const checkbox = document.createElement("input"); checkbox.type = "checkbox";
const taskLabel = document.createElement("span"); taskLabel.textContent = taskText;
checkbox.addEventListener("change", function() { if (this.checked) { completedTasks.appendChild(li); } else { incompleteTasks.appendChild(li); } });
li.appendChild(checkbox); li.appendChild(taskLabel);
incompleteTasks.appendChild(li);
taskInput.value = ""; });
clearCompletedBtn.addEventListener("click", function() { const completedTaskItems = completedTasks.querySelectorAll("li"); completedTaskItems.forEach(function(task) { task.remove(); }); });
|
最终效果(视频就不录了):

互联网产品开发流程及开发岗位:

可以当作手册查询的 html, css, js 网站:
https://developer.mozilla.org/zh-CN/docs/Web
NODEJS
异步的例子:
1 2 3 4 5 6 7 8 9 10 11 12 13
| const fs = require('fs');
fs.writeFile('1.txt', 'this is 1.txt', (err) => { if(err) { console.error(err); return; } console.log('file has been created successfully.'); })
console.log("Dose this happen after file?");
|
使用 nodejs 运行:
1 2
| Dose this happen after file? file has been created successfully.
|