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
浏览:780

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]删除
最新教程 更多>
  • 如何在 HTML 中使用 PHP?
    如何在 HTML 中使用 PHP?
    要在 HTML 中使用 PHP,必须用 PHP 开始标记 . 在本文中,我们将通过示例学习如何在 HTML 中使用 PHP。 PHP(超文本预处理器) 是一种用于 Web 开发的流行服务器端脚本语言。它允许您将动态内容嵌入到您的HTML。 在 HTML 中使用 PHP 的方法 要在 HTML 中有效...
    编程 发布于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_Word...
    编程 发布于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 窗口中无缝运行。尝试通过在括号前添加反斜杠来解决该问题也没有成功。调查显示,ma...
    编程 发布于2024-11-08
  • 什么时候可以从 C++ 标准库类继承?
    什么时候可以从 C++ 标准库类继承?
    通过继承扩展 C 标准库虽然人们通常认为从 C 标准库类继承是不可取的,但也有一些值得注意的例外.可识别的类继承确定标准库类是否用于继承可能具有挑战性。但是,以下准则可以提供一些见解:如果类具有虚方法,则它可能是继承的候选者。过多的“friend”声明表明存在封装问题,从而导致继承不太合适。模板应该...
    编程 发布于2024-11-08
  • 利用 AI 快速学习 Node.js - 第 2 天
    利用 AI 快速学习 Node.js - 第 2 天
    今天,我借助AI继续我的Node.js学习之旅,第2天的主题是Node.js中的模块系统。由于我已经熟悉 JavaScript,因此了解这种语言如何将代码组织成模块,从而使其更易于构建和重用是很有趣的。 理论部分:Node.js 中的模块基础知识 首先,我完成了理论部分,其中解释了两...
    编程 发布于2024-11-08
  • 优化 Next.js 应用性能的经过验证的技巧 ⚡️
    优化 Next.js 应用性能的经过验证的技巧 ⚡️
    优化 Web 应用程序的性能对于提供快速、流畅的用户体验至关重要。 借助 Next.js 这个强大的 React 框架,您可以利用许多内置功能来提高应用程序的速度和效率。 以下是让 Next.js 应用获得最佳性能的十个关键策略: 1. 仅加载您需要的 JavaScript 和 ...
    编程 发布于2024-11-08
  • 为什么 Python 和 Golang Zlib 产生不同的压缩输出?
    为什么 Python 和 Golang Zlib 产生不同的压缩输出?
    了解 Golang 和 Python Zlib 输出的差异使用 Zlib 压缩来压缩字符串时,Python 的 zlib 库会产生与Golang 的 zlib 实现。具体来说,第五个字节不同,Python 的值为 0,而 Golang 的值为 4。差异原因输出的差异源于来自 Python 和 Go ...
    编程 发布于2024-11-08
  • 如何在PHP中按扩展名高效过滤文件?
    如何在PHP中按扩展名高效过滤文件?
    在 PHP 中按扩展名高效过滤文件您希望根据文件扩展名过滤目录中的文件,特别是 . ini 文件。虽然 scandir() 提供目录中所有文件的列表,但它并不是过滤检索的最有效方法。利用 PHP 的 glob() 函数高效获取具有特定扩展名的文件,利用 PHP 的 glob() 函数。此函数采用模式...
    编程 发布于2024-11-08
  • FiveM x TypeScript
    FiveM x TypeScript
    FiveM 是 Grand Theft Auto V 的修改版,使您能够在由 Cfx.re 提供支持的定制专用服务器上玩多人游戏。 当您开发 FiveM 服务器时,您可以创建资源。这些资源可以用多种语言编写:Lua、C# 和 JavaScript。在本文中,我们将了解如何使用 TypeScript...
    编程 发布于2024-11-08

免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。

Copyright© 2022 湘ICP备2022001581号-3