This sets up a simple interface where users can input tasks and see them listed.

b) Styling with CSS
Now, let’s style the app to make it visually appealing. Here’s a basic example:

* {  box-sizing: border-box; /* Ensure consistent element sizing */}.container {  background: #add4f6; /* Light blue background for the container */  padding: 25px;  max-width: 760px; /* Maximum width of the container */  margin: 25px auto; /* Center the container */  overflow: hidden;  border-radius: 10px; /* Rounded corners */  border: 4px solid #7fa2de; /* Border color */  font-family: sans-serif; /* Font for the entire app */}h1,h2 {  margin: 0;  text-align: center;  text-transform: uppercase; /* Capitalized headings */}h2 {  font-size: 20px;  border-bottom: 1px solid #7fa2de; /* Divider below the title */  padding-bottom: 10px;  color: #575cab; /* Heading color */}.new-task-container {  text-align: center; /* Center alignment for new task input */}.box {  padding: 10px 15px;  border: 2px solid #7fa2de;  border-radius: 5px; /* Slightly rounded task boxes */  background: #fff; /* White background for task lists */  margin: 15px 0;}.todo-list {  float: left;  width: 46%; /* Incomplete tasks take up 46% width */}.complete-list {  float: right;  width: 46%; /* Completed tasks take up 46% width */}ul {  list-style: none; /* Remove default list styling */  padding: 0;  margin: 0;}li {  padding: 10px;  border-bottom: 1px dotted #ccc; /* Dashed separator between tasks */}.update {  float: right;  background-color: blue;  color: white;  border: 0;  padding: 3px 5px; /* Styling for the update button */}.delete {  float: right;  background-color: red;  color: white;  border: 0;  padding: 3px 5px; /* Styling for the delete button */}

This makes your app look clean and structured. You can customize the colors and layout as you like! ?

c) Adding Functionality with JavaScript
Now comes the fun part – adding JavaScript to make the app interactive! For a To-Do List, you want users to be able to add tasks and mark them as completed.

// Select DOM elements and assign them to variableslet newTask = document.querySelector(\\'#new-task\\');let form = document.querySelector(\\'form\\');let todoUl = document.querySelector(\\'#items\\');let completeUl = document.querySelector(\\'.complete-list ul\\');// Create a new task item with a checkbox and labellet createTask = function(task) {    let listItem = document.createElement(\\'li\\');    let checkBox = document.createElement(\\'input\\');    let label = document.createElement(\\'label\\');    label.innerText = task;    checkBox.type = \\'checkbox\\';    listItem.appendChild(checkBox);    listItem.appendChild(label);    return listItem;}// Add a new tasklet addTask = function(event) {    event.preventDefault();    let listItem = createTask(newTask.value);    todoUl.appendChild(listItem);    newTask.value = \\\"\\\"; // Clear input field after adding    // Bind new task to complete task function    bindInCompleteItems(listItem, completeTask);}// Move task to completed listlet completeTask = function() {    let listItem = this.parentNode;    let deleteBtn = document.createElement(\\'button\\');    deleteBtn.innerText = \\'Delete\\';    deleteBtn.className = \\'delete\\';    listItem.appendChild(deleteBtn);    // Remove checkbox and move task to completed list    let checkBox = listItem.querySelector(\\'input[type=\\\"checkbox\\\"]\\');    checkBox.remove();    completeUl.appendChild(listItem);    // Bind delete button to delete function    bindCompleteItems(listItem, deleteTask);}// Delete task from completed listlet deleteTask = function() {    let listItem = this.parentNode;    let ul = listItem.parentNode;    ul.removeChild(listItem);}// Bind incomplete tasks to complete task functionlet bindInCompleteItems = function(taskItem, checkboxClick) {    let checkBox = taskItem.querySelector(\\'input[type=\\\"checkbox\\\"]\\');    checkBox.onchange = checkboxClick;}// Bind completed tasks to delete functionlet bindCompleteItems = function(taskItem, deleteButtonClick) {    let deleteButton = taskItem.querySelector(\\'.delete\\');    deleteButton.onclick = deleteButtonClick;}// Loop through incomplete tasks to bind complete task functionfor(let i = 0; i < todoUl.children.length; i  ) {    bindInCompleteItems(todoUl.children[i], completeTask);}// Loop through completed tasks to bind delete functionfor(let i = 0; i < completeUl.children.length; i  ) {    bindCompleteItems(completeUl.children[i], deleteTask);}// Add task on form submitform.addEventListener(\\'submit\\', addTask);

5. Expanding the To-Do App: Features and Design
At this stage, you’ve created a fully functional To-Do List App that allows users to add, complete, and delete tasks. However, there are several ways you can expand and enhance the app both in terms of functionality and design:

a) Add Task Editing: You could allow users to edit a task after it’s been added. This would involve adding an \\\"Edit\\\" button next to each task, enabling users to modify the task name before saving it again.

b) Improve the Design: You can enhance the design by using CSS frameworks like Tailwind CSS or Bootstrap to make the app look more modern and responsive on different screen sizes. Experiment with animations for smoother transitions when tasks are added or removed.

6. Conclusion
? Congratulations! You’ve successfully built your first web application, a To-Do List App, using HTML, CSS, and JavaScript. ? Along the way, you learned how to structure your application using HTML, style it with CSS, and bring it to life with JavaScript. ✨ This project introduced you to the core aspects of frontend development, and you’re now equipped with the basic skills to build more complex applications. ?

","image":"http://www.luping.net/uploads/20241012/1728720010670a2c8a66a5b.jpg","datePublished":"2024-11-03T09:35:34+08:00","dateModified":"2024-11-03T09:35:34+08:00","author":{"@type":"Person","name":"luping.net","url":"https://www.luping.net/articlelist/0_1.html"}}
」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > 建立您的第一個 Web 應用程式:逐步指南

建立您的第一個 Web 應用程式:逐步指南

發佈於2024-11-03
瀏覽:957

Building Your First Web Application: A Step-by-Step Guide

Web development is an exciting field that enables you to create interactive, visually appealing applications. This article will guide you through building your very first web application: a To-Do List App. This project is an excellent introduction to HTML, CSS, and JavaScript, giving you a hands-on approach to frontend development.

New to Frontend Development?
If you're new to frontend development, check out our previous guide: Frontend Development for Beginners: Your Essential Starting Point to learn the basics of HTML, CSS, and JavaScript!

Table of Contents:
1. What is a Web Application?
2. Setting Up Your Development Environment
3. Core Frontend Technologies
2. Setting Up Your Development Environment
4. Building the To-Do List App
- Structuring the HTML
- Styling with CSS
- Adding Functionality with JavaScript
5. Expanding the To-Do App: Features and Design
6. Conclusion

1. What is a Web Application?
A web application is a software program that runs in a web browser. Unlike static websites, web applications are interactive, allowing users to perform tasks like adding tasks to a to-do list, completing them, and deleting them. You’ve probably used countless web applications, from social media platforms to online shopping websites.

2. Setting Up Your Development Environment
Before you start coding, make sure your environment is ready:

  • Code Editor: Use a code editor like VS Code, Sublime Text, or Atom.
  • Browser: Any modern browser will work. Google Chrome or Firefox are popular choices.
  • Basic Setup: Create a project folder where you’ll save your HTML, CSS, and JavaScript files.

3. Core Frontend Technologies

  • HTML (HyperText Markup Language): This is the foundation of your web app. It defines the structure and layout of the application.
  • CSS (Cascading Style Sheets): CSS styles your HTML content, making it visually appealing.
  • JavaScript: JavaScript adds interactivity to your web app, allowing users to perform actions like adding or deleting tasks.

4. Building the To-Do List App
Let’s dive into building your To-Do List Application. We’ll start by writing the HTML, then style it with CSS, and finally, add functionality with JavaScript.

Let’s set up a simple project structure:

  1. Create a new folder for your project.
  2. Inside it, create:
  • index.html: The main HTML file.
  • style.css: For styling the app.
  • script.js: Your JavaScript code.

You can now link the CSS and JavaScript files to your HTML using simple and

a) Structuring the HTML
Start with the basic layout of your web application. For example, if you're building a To-Do List, your HTML might look like this:


   
    To-Do App

To-Do App

Incomplete Tasks

Completed Tasks

  • Here Task Name

This sets up a simple interface where users can input tasks and see them listed.

b) Styling with CSS
Now, let’s style the app to make it visually appealing. Here’s a basic example:

* {
  box-sizing: border-box; /* Ensure consistent element sizing */
}

.container {
  background: #add4f6; /* Light blue background for the container */
  padding: 25px;
  max-width: 760px; /* Maximum width of the container */
  margin: 25px auto; /* Center the container */
  overflow: hidden;
  border-radius: 10px; /* Rounded corners */
  border: 4px solid #7fa2de; /* Border color */
  font-family: sans-serif; /* Font for the entire app */
}

h1,
h2 {
  margin: 0;
  text-align: center;
  text-transform: uppercase; /* Capitalized headings */
}

h2 {
  font-size: 20px;
  border-bottom: 1px solid #7fa2de; /* Divider below the title */
  padding-bottom: 10px;
  color: #575cab; /* Heading color */
}

.new-task-container {
  text-align: center; /* Center alignment for new task input */
}

.box {
  padding: 10px 15px;
  border: 2px solid #7fa2de;
  border-radius: 5px; /* Slightly rounded task boxes */
  background: #fff; /* White background for task lists */
  margin: 15px 0;
}

.todo-list {
  float: left;
  width: 46%; /* Incomplete tasks take up 46% width */
}

.complete-list {
  float: right;
  width: 46%; /* Completed tasks take up 46% width */
}

ul {
  list-style: none; /* Remove default list styling */
  padding: 0;
  margin: 0;
}

li {
  padding: 10px;
  border-bottom: 1px dotted #ccc; /* Dashed separator between tasks */
}

.update {
  float: right;
  background-color: blue;
  color: white;
  border: 0;
  padding: 3px 5px; /* Styling for the update button */
}

.delete {
  float: right;
  background-color: red;
  color: white;
  border: 0;
  padding: 3px 5px; /* Styling for the delete button */
}

This makes your app look clean and structured. You can customize the colors and layout as you like! ?

c) Adding Functionality with JavaScript
Now comes the fun part – adding JavaScript to make the app interactive! For a To-Do List, you want users to be able to add tasks and mark them as completed.

// Select DOM elements and assign them to variables
let newTask = document.querySelector('#new-task');
let form = document.querySelector('form');
let todoUl = document.querySelector('#items');
let completeUl = document.querySelector('.complete-list ul');

// Create a new task item with a checkbox and label
let createTask = function(task) {
    let listItem = document.createElement('li');
    let checkBox = document.createElement('input');
    let label = document.createElement('label');

    label.innerText = task;
    checkBox.type = 'checkbox';

    listItem.appendChild(checkBox);
    listItem.appendChild(label);

    return listItem;
}

// Add a new task
let addTask = function(event) {
    event.preventDefault();
    let listItem = createTask(newTask.value);
    todoUl.appendChild(listItem);
    newTask.value = ""; // Clear input field after adding

    // Bind new task to complete task function
    bindInCompleteItems(listItem, completeTask);
}

// Move task to completed list
let completeTask = function() {
    let listItem = this.parentNode;
    let deleteBtn = document.createElement('button');
    deleteBtn.innerText = 'Delete';
    deleteBtn.className = 'delete';
    listItem.appendChild(deleteBtn);

    // Remove checkbox and move task to completed list
    let checkBox = listItem.querySelector('input[type="checkbox"]');
    checkBox.remove();

    completeUl.appendChild(listItem);

    // Bind delete button to delete function
    bindCompleteItems(listItem, deleteTask);
}

// Delete task from completed list
let deleteTask = function() {
    let listItem = this.parentNode;
    let ul = listItem.parentNode;
    ul.removeChild(listItem);
}

// Bind incomplete tasks to complete task function
let bindInCompleteItems = function(taskItem, checkboxClick) {
    let checkBox = taskItem.querySelector('input[type="checkbox"]');
    checkBox.onchange = checkboxClick;
}

// Bind completed tasks to delete function
let bindCompleteItems = function(taskItem, deleteButtonClick) {
    let deleteButton = taskItem.querySelector('.delete');
    deleteButton.onclick = deleteButtonClick;
}

// Loop through incomplete tasks to bind complete task function
for(let i = 0; i 



5. Expanding the To-Do App: Features and Design
At this stage, you’ve created a fully functional To-Do List App that allows users to add, complete, and delete tasks. However, there are several ways you can expand and enhance the app both in terms of functionality and design:

a) Add Task Editing: You could allow users to edit a task after it’s been added. This would involve adding an "Edit" button next to each task, enabling users to modify the task name before saving it again.

b) Improve the Design: You can enhance the design by using CSS frameworks like Tailwind CSS or Bootstrap to make the app look more modern and responsive on different screen sizes. Experiment with animations for smoother transitions when tasks are added or removed.

6. Conclusion
? Congratulations! You’ve successfully built your first web application, a To-Do List App, using HTML, CSS, and JavaScript. ? Along the way, you learned how to structure your application using HTML, style it with CSS, and bring it to life with JavaScript. ✨ This project introduced you to the core aspects of frontend development, and you’re now equipped with the basic skills to build more complex applications. ?

版本聲明 本文轉載於:https://dev.to/asimachowdhury/building-your-first-web-application-a-step-by-step-guide-3po8?1如有侵犯,請聯絡[email protected]刪除
最新教學 更多>
  • ## 為什麼模板基底類別的多重繼承會導致成員函數解析不明確?
    ## 為什麼模板基底類別的多重繼承會導致成員函數解析不明確?
    消除多重繼承的歧義使用模板基類處理多重繼承時,會出現關於不明確成員函數解析的潛在問題。考慮以下場景:template <typename ... Types> class Base { public: template <typename T> typename st...
    程式設計 發佈於2024-11-08
  • 如何為字典條目等類別新增動態屬性?
    如何為字典條目等類別新增動態屬性?
    在類別中加入動態屬性在使用類比類別模擬資料庫結果集的過程中,出現了一個挑戰:如何指派動態屬性實例的屬性類似字典的屬性。這涉及創建行為類似於具有特定值的屬性的屬性。 最初,一種有前景的方法涉及使用以下方式分配屬性:setattr(self, k, property(lambda x: vs[i], s...
    程式設計 發佈於2024-11-08
  • 使用failsafe-go 庫實現微服務之間通訊的彈性
    使用failsafe-go 庫實現微服務之間通訊的彈性
    Let's start at the beginning. What is resilience? I like the definition in this post: The intrinsic ability of a system to adjust its functioning prio...
    程式設計 發佈於2024-11-08
  • 系統整合測試:確保無縫軟體集成
    系統整合測試:確保無縫軟體集成
    在軟體開發的動態環境中,確保系統的各個組件或模組無縫地協同工作對於提供可靠且高效能的軟體解決方案至關重要。這篇部落格文章深入探討了系統整合測試 (SIT),這是軟體測試生命週期中的關鍵階段,用於驗證整合組件之間的交互,確保系統的整體功能和可靠性。 什麼是系統整合測試? 系統整合測試 (SIT) ...
    程式設計 發佈於2024-11-08
  • 事件冒泡和捕獲 - 像 5 歲一樣學習
    事件冒泡和捕獲 - 像 5 歲一樣學習
    來吧,「像五歲一樣學習」只是一個短語——我不是在這裡講一個玩具故事!但我保證,如果你從頭到尾仔細閱讀,一切都會有意義。 事件冒泡和捕獲是在 JavaScript 中觸發事件時事件如何透過 DOM(文檔物件模型)傳播(或傳播)的兩個階段。現在,這個說法需要澄清事件傳播的概念。 事件...
    程式設計 發佈於2024-11-08
  • 如何將變數從一個頁面傳送到另一個 flutter/dart
    如何將變數從一個頁面傳送到另一個 flutter/dart
    您好,我目前正在嘗試在連接步驟期間將用戶的變數條目傳遞到我的應用程式的主頁,但我遇到錯誤,我不知道是什麼原因導致的,在我的頁面main (gamepage) 中,在男孩的孩子中,我想顯示控制器的地址,但是flutter 告訴我這個變數沒有定義! ! ! 你是我唯一的希望 import 'dart:...
    程式設計 發佈於2024-11-08
  • 如何在 HTML 中使用 PHP?
    如何在 HTML 中使用 PHP?
    要在HTML 中使用PHP,必須用PHP 開始標記. 在本文中,我們將透過範例學習如何在HTML 中使用PHP。 PHP(超文本預處理器) 是用於 Web 開發的流行伺服器端腳本語言。它允許您將動態內容嵌入到您的HTML。 在 HTML 中使用 PHP 的方法 要在 HTML 中有效使用 PHP...
    程式設計 發佈於2024-11-08
  • 使用 LangSmith Hub 改變您的工作流程:JavaScript 工程師的遊戲規則改變者
    使用 LangSmith Hub 改變您的工作流程:JavaScript 工程師的遊戲規則改變者
    分散的人工智能提示是否会减慢您的开发进程?了解 LangChain Hub 如何彻底改变您的工作流程,为 JavaScript 工程师提供无缝且高效的即时管理。 介绍 想象一下管理一个项目,其中关键信息分散在文件中。令人沮丧,对吧?这就是处理 AI 提示的开发人员面临的现实。 Lan...
    程式設計 發佈於2024-11-08
  • 如何在 PHP 中將數值轉換為字串表示形式?
    如何在 PHP 中將數值轉換為字串表示形式?
    將數值轉換為PHP 中的字串表示形式將數值轉換為PHP 中對應的字串版本是一項常見任務,尤其是在工作時與文字處理或面向使用者的應用程式。當處理特定範圍內的值時,這種轉換變得尤其重要,例如將數字從 1 到 99 轉換為其等效文字。 要執行此轉換,我們可以利用 PEAR 套件 Numbers_Words...
    程式設計 發佈於2024-11-08
  • 如何在 Bigquery 參數化查詢中傳遞結構數組
    如何在 Bigquery 參數化查詢中傳遞結構數組
    在Google的Bigquery中,SQL查詢可以參數化。如果您不熟悉這個概念,它基本上意味著您可以將 SQL 查詢編寫為參數化模板,如下所示: INSERT INTO mydataset.mytable(columnA, columnB) VALUES (@valueA, @valueB)...
    程式設計 發佈於2024-11-08
  • 如何使用 Python“for”循環實現 C/C++ 風格循環?
    如何使用 Python“for”循環實現 C/C++ 風格循環?
    在Python 中實現C/C 風格循環:“for”循環在Python 中,循環提供了一種用於迭代序列的通用機制。雖然 Python 的「for」循環語法與其 C/C 對應部分不同,但實現類似的功能仍然是可行的。 考慮C/C 中的以下循環:for(int k = 1; k <= c; k = ...
    程式設計 發佈於2024-11-08
  • Laravel 入門:查詢產生器初學者指南
    Laravel 入門:查詢產生器初學者指南
    Laravel 的 查询生成器 提供了一个强大、流畅的界面,用于在 PHP 中构建 SQL 查询。它允许您以富有表现力的、类似 SQL 的语法与数据库交互,同时抽象出大部分复杂性。 我们将演练 Laravel 应用程序中的典型用例,使用查询生成器执行各种任务,例如选择、插入、更新和删除数据。 ...
    程式設計 發佈於2024-11-08
  • 如何截斷長分頁清單以增強使用者體驗?
    如何截斷長分頁清單以增強使用者體驗?
    截斷長頁面清單以實現高效分頁分頁是任何顯示大量資料的網站或應用程式的重要組成部分,因為它允許用戶以可管理的區塊的方式瀏覽它。但是,如果以簡單的方式實現,分頁可能會導致頁面清單過長,特別是當應用於具有大量頁面的資料集時。 為了緩解此問題,有必要截斷這些頁面清單為使用者提供更簡潔的導航選項。在本文中,我...
    程式設計 發佈於2024-11-08
  • 如何在 JavaScript 中展平數組
    如何在 JavaScript 中展平數組
    使用遞歸和 while 循環是更簡單的方法之一 export default function flatten(value) { const arr = [] const flat = (a) => { let counter = 0 console.log(a) ...
    程式設計 發佈於2024-11-08
  • 為什麼我無法在 Powershell 中執行複雜的 ImageMagick 命令,但它們可以在 CMD 中運行?
    為什麼我無法在 Powershell 中執行複雜的 ImageMagick 命令,但它們可以在 CMD 中運行?
    ImageMagick 指令無法在Powershell 中運行,但在cmd 視窗中執行沒有問題在嘗試使用ImageMagick 指令時,使用者在Powershell 視窗中執行它們時遇到了挑戰。這些命令在 cmd 視窗中無縫運行。嘗試在括號前添加反斜線來解決該問題也沒有成功。調查顯示,magick指...
    程式設計 發佈於2024-11-08

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3