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
瀏覽:556

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]刪除
最新教學 更多>
  • 為什麼不````''{margin:0; }`始終刪除CSS中的最高邊距?
    為什麼不````''{margin:0; }`始終刪除CSS中的最高邊距?
    在CSS 問題:不正確的代碼: 全球範圍將所有餘量重置為零,如提供的代碼所建議的,可能會導致意外的副作用。解決特定的保證金問題是更建議的。 例如,在提供的示例中,將以下代碼添加到CSS中,將解決餘量問題: body H1 { 保證金頂:-40px; } 此方法更精確,避免了由全局保證金重置...
    程式設計 發佈於2025-04-18
  • 反射動態實現Go接口用於RPC方法探索
    反射動態實現Go接口用於RPC方法探索
    在GO 使用反射來實現定義RPC式方法的界面。例如,考慮一個接口,例如:鍵入myService接口{ 登錄(用戶名,密碼字符串)(sessionId int,錯誤錯誤) helloworld(sessionid int)(hi String,錯誤錯誤) } 替代方案而不是依靠反射...
    程式設計 發佈於2025-04-18
  • 為什麼我的CSS背景圖像出現?
    為什麼我的CSS背景圖像出現?
    故障排除:CSS背景圖像未出現 ,您的背景圖像儘管遵循教程說明,但您的背景圖像仍未加載。圖像和样式表位於相同的目錄中,但背景仍然是空白的白色帆布。 而不是不棄用的,您已經使用了CSS樣式: bockent {背景:封閉圖像文件名:背景圖:url(nickcage.jpg); 如果您的html,cs...
    程式設計 發佈於2025-04-18
  • 為什麼我在Silverlight Linq查詢中獲得“無法找到查詢模式的實現”錯誤?
    為什麼我在Silverlight Linq查詢中獲得“無法找到查詢模式的實現”錯誤?
    查詢模式實現缺失:解決“無法找到”錯誤在Silverlight應用程序中,嘗試使用LINQ建立LINQ連接以錯誤而實現的數據庫”,無法找到查詢模式的實現。”當省略LINQ名稱空間或查詢類型缺少IEnumerable 實現時,通常會發生此錯誤。 解決問題來驗證該類型的質量是至關重要的。在此特定實例...
    程式設計 發佈於2025-04-18
  • 如何限制動態大小的父元素中元素的滾動範圍?
    如何限制動態大小的父元素中元素的滾動範圍?
    在交互式接口中實現垂直滾動元素的CSS高度限制問題:考慮一個佈局,其中我們具有與用戶垂直滾動一起移動的可滾動地圖div,同時與固定的固定sidebar保持一致。但是,地圖的滾動無限期擴展,超過了視口的高度,阻止用戶訪問頁面頁腳。 $("#map").css({ margin...
    程式設計 發佈於2025-04-18
  • eval()vs. ast.literal_eval():對於用戶輸入,哪個Python函數更安全?
    eval()vs. ast.literal_eval():對於用戶輸入,哪個Python函數更安全?
    稱量()和ast.literal_eval()中的Python Security 在使用用戶輸入時,必須優先確保安全性。強大的python功能eval()通常是作為潛在解決方案而出現的,但擔心其潛在風險。 This article delves into the differences betwee...
    程式設計 發佈於2025-04-18
  • 如何克服PHP的功能重新定義限制?
    如何克服PHP的功能重新定義限制?
    克服PHP的函數重新定義限制在PHP中,多次定義一個相同名稱的函數是一個no-no。嘗試這樣做,如提供的代碼段所示,將導致可怕的“不能重新列出”錯誤。 但是,PHP工具腰帶中有一個隱藏的寶石:runkit擴展。它使您能夠靈活地重新定義函數。 runkit_function_renction_...
    程式設計 發佈於2025-04-18
  • 如何使用不同數量列的聯合數據庫表?
    如何使用不同數量列的聯合數據庫表?
    合併列數不同的表 當嘗試合併列數不同的數據庫表時,可能會遇到挑戰。一種直接的方法是在列數較少的表中,為缺失的列追加空值。 例如,考慮兩個表,表 A 和表 B,其中表 A 的列數多於表 B。為了合併這些表,同時處理表 B 中缺失的列,請按照以下步驟操作: 確定表 B 中缺失的列,並將它們添加到表的...
    程式設計 發佈於2025-04-18
  • 人臉檢測失敗原因及解決方案:Error -215
    人臉檢測失敗原因及解決方案:Error -215
    錯誤處理:解決“ error:( - 215)!empty()in Function openCv in Function MultSiscale中的“檢測”中的錯誤:在功能檢測中。”當Face Cascade分類器(即面部檢測至關重要的組件)未正確加載時,通常會出現此錯誤。 要解決此問題,必...
    程式設計 發佈於2025-04-18
  • 如何使用Java.net.urlConnection和Multipart/form-data編碼使用其他參數上傳文件?
    如何使用Java.net.urlConnection和Multipart/form-data編碼使用其他參數上傳文件?
    使用http request 上傳文件上傳到http server,同時也提交其他參數,java.net.net.urlconnection and Multipart/form-data Encoding是普遍的。 Here's a breakdown of the process:Mu...
    程式設計 發佈於2025-04-18
  • JavaScript中如何動態訪問全局變量?
    JavaScript中如何動態訪問全局變量?
    在JavaScript 一種方法是使用窗口對象存儲和檢索變量。通過引用全局範圍,可以使用其名稱動態訪問變量。 //一個腳本 var somevarname_10 = 20; //另一個腳本 window.all_vars = {}; window.all_vars ['somevarna...
    程式設計 發佈於2025-04-18
  • 為什麼我會收到MySQL錯誤#1089:錯誤的前綴密鑰?
    為什麼我會收到MySQL錯誤#1089:錯誤的前綴密鑰?
    mySQL錯誤#1089:錯誤的前綴鍵錯誤descript [#1089-不正確的前綴鍵在嘗試在表中創建一個prefix鍵時會出現。前綴鍵旨在索引字符串列的特定前綴長度長度,可以更快地搜索這些前綴。 了解prefix keys `這將在整個Movie_ID列上創建標準主鍵。主密鑰對於唯一識...
    程式設計 發佈於2025-04-18
  • 您如何在Laravel Blade模板中定義變量?
    您如何在Laravel Blade模板中定義變量?
    在Laravel Blade模板中使用Elegance 在blade模板中如何分配變量對於存儲以後使用的數據至關重要。在使用“ {{}}”分配變量的同時,它可能並不總是最優雅的解決方案。 幸運的是,Blade通過@php Directive提供了更優雅的方法: $ old_section =...
    程式設計 發佈於2025-04-18
  • Java開發者如何保護數據庫憑證免受反編譯?
    Java開發者如何保護數據庫憑證免受反編譯?
    在java 在單獨的配置文件保護數據庫憑證的最有效方法中存儲憑據是將它們存儲在單獨的配置文件中。該文件可以在運行時加載,從而使登錄數據從編譯的二進製文件中遠離。 使用prevereness class import java.util.prefs.preferences; 公共類示例{ 首選...
    程式設計 發佈於2025-04-18
  • 如何在JavaScript對像中動態設置鍵?
    如何在JavaScript對像中動態設置鍵?
    在嘗試為JavaScript對象創建動態鍵時,如何使用此Syntax jsObj['key' i] = 'example' 1;不工作。正確的方法採用方括號: jsobj ['key''i] ='example'1; 在JavaScript中,數組是一...
    程式設計 發佈於2025-04-18

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

Copyright© 2022 湘ICP备2022001581号-3