Strike It چالش 3 از جلسهی 7، آسان
تیکها کار میکنند ولی کار انجامشده فرقی نمیکند. در <style> یک قانون برای کلاس done بنویس که روی متن خط بکشد (text-decoration: line-through) و رنگش را gray کند.
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body { font-family: Tahoma, sans-serif; max-width: 420px; margin: 0 auto; padding: 12px; }
li { padding: 8px 0; font-size: 18px; }
form { display: flex; column-gap: 8px; }
input { font-size: 16px; min-height: 44px; }
input[type="checkbox"] { min-height: 0; width: 24px; height: 24px; }
button { font-size: 16px; min-height: 44px; }
</style>
<h1>My Tasks</h1>
<ul id="list"></ul>
<script>
let todos = [
{ text: "Feed the cat", done: false },
{ text: "Read a book", done: false },
{ text: "Tidy my desk", done: false },
];
function render() {
let list = document.getElementById("list");
list.textContent = "";
for (let i = 0; i < todos.length; i++) {
let li = document.createElement("li");
let box = document.createElement("input");
box.type = "checkbox";
box.checked = todos[i].done;
box.onchange = function () { toggle(i); };
let span = document.createElement("span");
span.textContent = todos[i].text;
let del = document.createElement("button");
del.textContent = "Delete";
del.className = "del";
del.onclick = function () { removeAt(i); };
if (todos[i].done) li.classList.add("done");
li.append(box, span, del);
list.appendChild(li);
}
}
function toggle(i) {
todos[i].done = !todos[i].done;
render();
}
function removeAt(i) {
todos.splice(i, 1);
render();
}
render();
</script>
راهنما و جواب این چالش · برگشت به درس جلسهی 7: حذف و تیک · چالش بعدی: 3 of 5 Done
بیشتر بخوان: جاوااسکریپت چیست؟ از دکمهی وب تا Node.js