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

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]删除
最新教程 更多>
  • 为什么Microsoft Visual C ++无法正确实现两台模板的实例?
    为什么Microsoft Visual C ++无法正确实现两台模板的实例?
    [2明确担心Microsoft Visual C(MSVC)在正确实现两相模板实例化方面努力努力。该机制的哪些具体方面无法按预期运行?背景:说明:的初始Syntax检查在范围中受到限制。它未能检查是否存在声明名称的存在,导致名称缺乏正确的声明时会导致编译问题。为了说明这一点,请考虑以下示例:一个符合...
    编程 发布于2025-02-19
  • 如何可靠地检查MySQL表中的列存在?
    如何可靠地检查MySQL表中的列存在?
    在mySQL中确定列中的列存在,验证表中的列存在与与之相比有点困惑其他数据库系统。常用的方法:如果存在(从信息_schema.columns select * * where table_name ='prefix_topic'和column_name =&...
    编程 发布于2025-02-19
  • Java是否允许多种返回类型:仔细研究通用方法?
    Java是否允许多种返回类型:仔细研究通用方法?
    在java中的多个返回类型:一个误解介绍,其中foo是自定义类。该方法声明似乎拥有两种返回类型:列表和E。但是,情况确实如此吗?通用方法:拆开神秘 [方法仅具有单一的返回类型。相反,它采用机制,如钻石符号“ ”。分解方法签名: :本节定义了一个通用类型参数,E。它表示该方法接受扩展FOO类的任何...
    编程 发布于2025-02-19
  • 为什么使用固定定位时,为什么具有100%网格板柱的网格超越身体?
    为什么使用固定定位时,为什么具有100%网格板柱的网格超越身体?
    网格超过身体,用100%grid-template-columns 问题:考虑以下CSS和HTML: position:fixed; grid-template-columns:40%60%; grid-gap:5px; 背景:#eee; 当位置未固定时,网格将正确显示。但是,当...
    编程 发布于2025-02-19
  • 在没有密码提示的情况下,如何在Ubuntu上安装MySQL?
    在没有密码提示的情况下,如何在Ubuntu上安装MySQL?
    在ubuntu 使用debconf-set-selections 在安装过程中避免密码提示mysql root用户。这需要以下步骤: sudo debconf-set-selections
    编程 发布于2025-02-19
  • 如何使用组在MySQL中旋转数据?
    如何使用组在MySQL中旋转数据?
    在关系数据库中使用mysql组使用mysql组来调整查询结果。在这里,我们面对一个共同的挑战:使用组的组将数据从基于行的基于列的基于列的转换。通过子句以及条件汇总函数,例如总和或情况。让我们考虑以下查询: select d.data_timestamp, sum(data_id = 1 tata...
    编程 发布于2025-02-19
  • \“(1)vs.(;;):编译器优化是否消除了性能差异?\”
    \“(1)vs.(;;):编译器优化是否消除了性能差异?\”
    答案:在大多数现代编译器中,while(1)和(1)和(;;)之间没有性能差异。 说明: perl: S-> 7 8 unstack v-> 4 -e语法ok 在GCC中,两者都循环到相同的汇编代码中,如下所示:。 globl t_时 t_时: .l2: movl $ .lc0,�i ...
    编程 发布于2025-02-19
  • 为什么箭头函数在IE11中引起语法错误?如何修复它们?
    为什么箭头函数在IE11中引起语法错误?如何修复它们?
    为什么arrow functions在IE 11 中引起语法错误。 IE 11不支持箭头函数,导致语法错误。这使用传统函数语法来定义与原始箭头函数相同的逻辑。 IE 11现在将正确识别并执行代码。
    编程 发布于2025-02-19
  • 'exec()
    'exec()
    Exec对本地变量的影响: exec function,python staple,用于动态代码执行的python staple,提出一个有趣的Query:它可以在函数中更新局部变量吗?在Python 3中,以下代码代码无法更新本地变量,如人们所期望的:代替预期的'3',它令人震...
    编程 发布于2025-02-19
  • 如何从Python中的字符串中删除表情符号:固定常见错误的初学者指南?
    如何从Python中的字符串中删除表情符号:固定常见错误的初学者指南?
    从python 导入编解码器 导入 text = codecs.decode('这狗\ u0001f602'.encode('utf-8'),'utf-8') 印刷(文字)#带有表情符号 emoji_pattern = re.compile(“ [”...
    编程 发布于2025-02-19
  • 如何检查对象是否具有Python中的特定属性?
    如何检查对象是否具有Python中的特定属性?
    方法来确定对象属性存在寻求一种方法来验证对象中特定属性的存在。考虑以下示例,其中尝试访问不确定属性会引起错误: >>> a = someClass() >>> A.property Trackback(最近的最新电话): 文件“ ”,第1行, AttributeError:SomeClass实...
    编程 发布于2025-02-19
  • 如何在JavaScript对象中动态设置键?
    如何在JavaScript对象中动态设置键?
    如何为JavaScript对象变量创建动态键,尝试为JavaScript对象创建动态键,使用此Syntax jsObj['key' i] = 'example' 1;将不起作用。正确的方法采用方括号:他们维持一个长度属性,该属性反映了数字属性(索引)和一个数字属性的数量。标准对象没有模仿这...
    编程 发布于2025-02-19
  • 版本5.6.5之前,使用current_timestamp与时间戳列的current_timestamp与时间戳列有什么限制?
    版本5.6.5之前,使用current_timestamp与时间戳列的current_timestamp与时间戳列有什么限制?
    在默认值中使用current_timestamp或mysql版本中的current_timestamp或在5.6.5 这种限制源于遗产实现的关注,这些限制需要为Current_timestamp功能提供特定的实现。消息和相关问题 current_timestamp值: 创建表`foo`( `...
    编程 发布于2025-02-19
  • 如何使用PHP从XML文件中有效地检索属性值?
    如何使用PHP从XML文件中有效地检索属性值?
    从php 您的目标可能是检索“ varnum”属性值,其中提取数据的传统方法可能会使您留下PHP陷入困境。使用simplexmlelement :: attributes()函数提供了简单的解决方案。此函数可访问对XML元素作为关联数组的属性: - > attributes()为$ attr...
    编程 发布于2025-02-19
  • 哪种方法更有效地用于点 - 填点检测:射线跟踪或matplotlib \的路径contains_points?
    哪种方法更有效地用于点 - 填点检测:射线跟踪或matplotlib \的路径contains_points?
    在Python 射线tracing方法 matplotlib路径对象表示多边形。它检查给定点是否位于定义路径内。 This function is often faster than the ray tracing approach, as seen in the code snippet pr...
    编程 发布于2025-02-19

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

Copyright© 2022 湘ICP备2022001581号-3