WEB前端小練習——記事本

一、登陸頁面

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>記事本登錄注冊</title><link rel="stylesheet" href="../css/login.css">
</head><body><div id="app"><!-- 登錄頁面 --><div v-show="isLoginPage"><h2>登錄</h2><form><input v-model="loginUsername" placeholder="用戶名" /><input v-model="loginPassword" placeholder="密碼" /><button type="button" @click="login">登錄</button><button type="button" @click="showRegisterPage">注冊</button></form></div><!-- 注冊頁面 --><div v-show="isRegisterPage"><h2>注冊</h2><form><input v-model="registerUsername" placeholder="用戶名" /><input v-model="registerPassword" placeholder="密碼" type="password" /><button type="button" @click="register">注冊</button><button type="button" @click="showLoginPage">返回登錄</button></form></div></div><script src="https://cdn.jsdelivr.net/npm/vue@2"></script><script src="../js/login.js"></script>
</body></html>
body {font-family: Arial, sans-serif;display: flex;justify-content: center;align-items: center;min-height: 100vh;margin: 0;background-color: #f4f4f4;
}div {background-color: white;padding: 20px;border-radius: 5px;box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);text-align: center;
}h2 {text-align: center;
}input {width: 80%;padding: 10px;margin-bottom: 15px;border: 1px solid #ccc;border-radius: 3px;
}button {width: 20%;padding: 10px;background-color: #4CAF50;color: white;border: none;border-radius: 3px;cursor: pointer;margin: 30px;
}button:hover {background-color: #45a049;
}    

new Vue({el: '#app',data: {isLoginPage: true,isRegisterPage: false,isLoggedIn: false,loginUsername: '',loginPassword: '',registerUsername: '',registerPassword: '',registeredUsers: [], // 存儲已注冊用戶信息的數組usernamesSet: new Set(), // 用于確保用戶名唯一性的Setnotes: [],},mounted() {const storedUsers = localStorage.getItem('registeredUsers');if (storedUsers) {this.registeredUsers = JSON.parse(storedUsers);this.registeredUsers.forEach(user => {this.usernamesSet.add(user.username);});}},methods: {login() {const inputUsername = this.loginUsername;const inputPassword = this.loginPassword;const user = this.registeredUsers.find(u => u.username === inputUsername && u.password === inputPassword);if (user) {console.log('登錄成功,跳轉到指定頁面');window.location.href = '../html/index.html';} else {alert('用戶名或密碼錯誤,請重試!');}},register() {const usernamePattern = /^[a-zA-Z0-9]+$/;const passwordPattern = /.{6,}/;if (!this.registerUsername.match(usernamePattern)) {alert('用戶名只能包含字母和數字');return;}if (!this.registerPassword.match(passwordPattern)) {alert('密碼長度至少為6位');return;}if (this.usernamesSet.has(this.registerUsername)) {alert('該用戶名已注冊,請更換用戶名');return;}const userId = Date.now(); // 使用時間戳作為唯一IDconst newUser = {id: userId,username: this.registerUsername,password: this.registerPassword};this.registeredUsers.push(newUser);this.usernamesSet.add(this.registerUsername);localStorage.setItem('registeredUsers', JSON.stringify(this.registeredUsers));alert('注冊成功');console.log('已注冊用戶數組:', this.registeredUsers);this.isRegisterPage = false;this.isLoginPage = true;},showRegisterPage() {this.isLoginPage = false;this.isRegisterPage = true;},showLoginPage() {this.isRegisterPage = false;this.isLoginPage = true;}}
});

二、記事本頁面

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>記事本</title><!-- 引入重置樣式表 --><link href="../css/normalize.css" /><link href="../css/reset.css" /><link href="../css/index.css" rel="stylesheet" />
</head><body><!-- 引入 Vue --><script src="https://cdn.jsdelivr.net/npm/vue@2"></script><div id="contain"><div id="box"><div id="header"><span>記事本</span></div><div id="main"><div id="mainTop"><!-- 輸入框綁定 message 數據,按下回車鍵或點擊按鈕觸發 add 方法 --><input id="text" v-model="message" placeholder="just to do it!" @keyup.enter="add" /><button id="add" v-on:click="add">新增筆記</button><!-- 輸入框綁定 message 數據,按下回車鍵或點擊按鈕觸發 add 方法 --><br /><input id="search" v-model="searchKeyword" placeholder="搜索筆記" /><button id="check" v-on:click="select">查詢筆記</button></div><div id="mainBottom"><!-- 使用 ul 和 v-for 渲染筆記列表 --><ul><li v-for="(item, index) in searchResult.length > 0? searchResult : filteredNotesList" :key="index"><!-- 筆記內容展示部分 --><!-- 根據 delMuch 狀態顯示復選框,并綁定 checked 屬性 --><input type="checkbox" v-if="delMuch" v-model="item.checked"><span id="order">{{index + 1}}&nbsp;&nbsp;&nbsp;&nbsp;<!-- 根據 isEditing 狀態顯示文本或輸入框 --><!--根據 item.isEditing 的狀態來決定顯示筆記文本還是輸入框。當 isEditing 為 false 時顯示筆記文本,為 true 時顯示輸入框,并且輸入框通過 v-model 綁定 tempEditValue,用于編輯筆記內容。--><label v-if="!item.isEditing" id="content">{{item.text}}</label><input id="newMessage" v-else v-model="tempEditValue" type="text"></span><span id="right"><!-- 根據 isEditing 狀態顯示不同按鈕 --><button v-if="!item.isEditing" id="edit" @click="edit(index)">編輯</button><!--現在根據 item.isEditing 的狀態切換顯示不同按鈕。當處于非編輯狀態時顯示 “編輯” 按鈕,點擊后進入編輯狀態;進入編輯狀態后顯示 “確定” 和 “取消” 按鈕,分別用于確認修改和取消修改。--><button v-else id="confirm" @click="confirmEdit(index)">確定</button><button v-else id="cancel" @click="cancelEdit(index)">取消</button><button id="del" @click="del(index)">刪除</button></span></span></li></ul></div></div><div id="footer" v-show="NotesList.length > 0"><!-- 顯示筆記數量 --><span id="count">共有{{count}}條筆記</span><!-- 點擊按鈕觸發批量刪除和清空操作 --><button id="delMany" v-on:click="delMany" class="delS">批量刪除</button><button id="clear" v-on:click="clear">清空記事本</button></div></div></div><!-- 引入優化后的 JS 文件 --><script src="../js/index.js"></script>
</body></html>
/* 全局設置,將 box-sizing 設置為 border-box,避免尺寸計算問題 */
* {box-sizing: border-box;
}body {background-image: url(../src/img/image.png);background-size: cover;background-repeat: no-repeat;
}#box {position: absolute;top: 50%;left: 50%;transform: translate(-50%, -50%);
}#header {background-color: rgb(177, 223, 79, .8);width: 830px;height: 80px;border: 1px solid black;font-size: 25px;text-align: center;line-height: 80px;
}#main {width: 830px;height: 360px;border-left: 1px solid black;border-right: 1px solid black;background-color: rgb(255, 255, 255, .8);overflow: hidden;
}#mainTop {height: 60px;border: 1px solid black;display: flex;align-items: center;
}#text,
#search {width: 60%;height: 60px;box-sizing: border-box;font-size: 20px;float: left;
}#add,
#check {width: 15%;height: 60px;font-size: 17px;box-sizing: border-box;float: left;
}#mainBottom {height: 300px;overflow: auto;border: 1px solid black;position: relative;
}#newMessage,
#content {display: inline-block;height: 40px;line-height: 40px;width: 620px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;font-size: 20px;position: relative;vertical-align: middle;
}#footer {width: 830px;height: 70px;border: 1px solid black;background-color: rgba(177, 223, 79, .8);text-align: center;line-height: 70px;display: flex;align-items: center;position: relative;
}#text::placeholder {font-size: 22px;color: rgba(177, 220, 100, 1);padding-left: 30px;
}#search::placeholder {padding-left: 30px;
}#count {position: absolute;left: 10px;
}ul {padding: 0;margin: 0;
}li {height: 40px;box-sizing: border-box;display: flex;align-items: center;line-height: 40px;
}li:nth-child(2n + 1) {background-color: rgba(128, 128, 150, .3);
}#delMany {background-color: white;height: 40px;position: absolute;width: 90px;right: 120px;
}#clear {background-color: white;height: 40px;position: absolute;width: 90px;right: 10px;
}#right {right: 15px;position: absolute;font-size: 18px;
}#confirm,
#edit {margin-right: 8px;width: 45px;height: 30px;
}#del {width: 45px;height: 30px;
}#order {padding-left: 20px;
}
var app = new Vue({el: "#contain",data: {NotesList: [],count: 0,message: "",delMuch: false,tempEditValue: '',selectedCategory: '',searchKeyword: '',priorities: ['高', '中', '低'],selectedPriority: '',searchResult: [],searchResultCount: 0},computed: {filteredNotesList() {let filtered = this.NotesList;if (this.selectedCategory) {filtered = filtered.filter(item => item.category === this.selectedCategory);}if (this.searchKeyword) {const keyword = this.searchKeyword.toLowerCase();filtered = filtered.filter(item => item.text.toLowerCase().includes(keyword));}if (this.selectedPriority) {filtered = filtered.filter(item => item.priority === this.selectedPriority);}return filtered;},highlightedSearchResult() {return this.searchResult.map(item => {const keyword = this.searchKeyword;if (keyword) {const regex = new RegExp(keyword, 'gi');item.highlightedText = item.text.replace(regex, '<mark>$&</mark>');} else {item.highlightedText = item.text;}return item;});}},watch: {searchKeyword: function (newKeyword) {this.select();}},methods: {clear: function () {const confirmation = confirm('你確定要清空記事本嗎');if (confirmation) {this.NotesList = [];this.count = 0;this.saveNotesToLocalStorage();alert('操作已執行!');} else {alert('操作已取消。');}},add: function () {const input = this.message.trim();if (input) {this.NotesList.unshift({text: input,isEditing: false,checked: false,category: '工作',priority: '中'});this.count++;this.message = "";if (this.searchKeyword) {this.select();}this.saveNotesToLocalStorage();} else {alert("請輸入有效內容");}},edit: function (index) {if (this.filteredNotesList[index]) {const realIndex = this.NotesList.indexOf(this.filteredNotesList[index]);this.NotesList[realIndex].isEditing = true;this.tempEditValue = this.NotesList[realIndex].text;}},confirmEdit: function (index) {const newText = this.tempEditValue.trim();if (newText && this.filteredNotesList[index]) {const realIndex = this.NotesList.indexOf(this.filteredNotesList[index]);this.NotesList[realIndex].text = newText;}if (this.filteredNotesList[index]) {const realIndex = this.NotesList.indexOf(this.filteredNotesList[index]);this.NotesList[realIndex].isEditing = false;}if (this.searchKeyword) {this.select();}this.saveNotesToLocalStorage();},cancelEdit: function (index) {if (this.filteredNotesList[index]) {const realIndex = this.NotesList.indexOf(this.filteredNotesList[index]);this.NotesList[realIndex].isEditing = false;this.tempEditValue = this.NotesList[realIndex].text;}},del: function (index) {if (this.filteredNotesList.length > 0 && index >= 0 && index < this.filteredNotesList.length) {const realIndex = this.NotesList.indexOf(this.filteredNotesList[index]);this.NotesList.splice(realIndex, 1);this.count--;if (this.searchKeyword) {this.select();}this.saveNotesToLocalStorage();}},delMany: function () {this.delMuch = true;const originalLength = this.NotesList.length;this.NotesList = this.NotesList.filter(item => !item.checked);const deletedCount = originalLength - this.NotesList.length;if (deletedCount > 0) {this.count = this.NotesList.length;this.delMuch = false;const isConfirmed = confirm('你確定要刪除選中的筆記嗎?');if (isConfirmed) {alert(`已成功刪除 ${deletedCount} 條筆記`);}}if (this.searchKeyword) {this.select();}this.saveNotesToLocalStorage();},select: function () {const keyword = this.searchKeyword.trim().toLowerCase();if (keyword) {this.searchResult = this.NotesList.filter(item => item.text.toLowerCase().includes(keyword));this.searchResultCount = this.searchResult.length;if (this.searchResultCount === 0) {alert('沒有查詢到相關筆記');} else {alert(`查詢到 ${this.searchResultCount} 條相關筆記`);}} else {this.searchResult = [];this.searchResultCount = 0;}},addOrSearch: function (event) {if (event.key === 'Enter') {if (event.ctrlKey) {this.select();} else {this.add();}}},saveNotesToLocalStorage() {localStorage.setItem('notes', JSON.stringify(this.NotesList));},loadNotesFromLocalStorage() {const notes = localStorage.getItem('notes');if (notes) {this.NotesList = JSON.parse(notes);this.count = this.NotesList.length;}}},mounted() {this.loadNotesFromLocalStorage();}
});

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/79603.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/79603.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/79603.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

[ACTF2020 新生賽]Include [ACTF2020 新生賽]Exec

[ACTF2020 新生賽]Include 因為前端過濾的太多了 所以直接使用 日志包含 搞 包含這個 /var/log/nginx/access.log [ACTF2020 新生賽]Include蟻劍連接 翻看 flag{1ce7a81e-0339-44ef-a398-a7784d3efe37} [ACTF2020 新生賽]Exec [ACTF2020 新生賽]Exec 127.0.0.1 |echo <?…

VFS Global 攜手 SAP 推動數字化轉型

2025年5月2日&#xff0c;SAP 公司宣布&#xff0c;全球領先的簽證、領事和技術服務提供商 VFS Global 將采用 SAP 的多項核心軟件解決方案&#xff0c;推動其全球政務服務和跨境流動解決方案邁向全面數字化和智能化。此次合作標志著 VFS Global 在 AI 賦能的政府科技&#xff…

GTC2025全球流量大會:領馭科技以AI云端之力,助力中國企業出海破浪前行

在全球化與數字化浪潮下&#xff0c;AI技術正成為中國企業出海的重要驅動力。一方面&#xff0c;AI通過語言處理、數據分析等能力顯著提升出海企業的運營效率與市場適應性&#xff0c;尤其在東南亞等新興市場展現出"高性價比場景適配"的競爭優勢&#xff1b;另一方面…

安全漏洞掃描費用受哪些因素影響?市場價格區間是多少?

安全漏洞掃描費用是個復雜且關鍵的話題。它涉及多種影響因素。合理的費用可讓企業有效防范安全風險。下面我們深入探討一番。 市場價格區間 安全漏洞掃描的費用在市場上差別很大。小型企業進行簡單掃描&#xff0c;可能只要幾千元。大型企業做全面的深度掃描&#xff0c;費用…

n8n工作流自動化平臺的實操:解決中文亂碼

解決問題&#xff1a; 通過ftp讀取中文內容的文件&#xff0c;會存在亂碼&#xff0c;如下圖&#xff1a; 解決方案 1.詳見《安裝 iconv-lite》 2.在code節點&#xff0c;寫如下代碼&#xff1a; const iconv require(iconv-lite);const items $input.all(); items.forEa…

豪越科技消防立庫方案:實現應急物資高效管理

在消防救援工作中&#xff0c;應急物資管理是至關重要的一環。然而&#xff0c;當前應急物資管理的現狀卻令人擔憂。傳統的應急物資管理方式存在諸多弊端&#xff0c;嚴重影響了消防救援的效率和效果。 走進一些傳統的消防倉庫&#xff0c;映入眼簾的往往是雜亂無章的存儲場景。…

zabbix 重置登錄密碼

概述 本節介紹在 Zabbix 中重置用戶密碼的步驟。 步驟 如果您忘記了 Zabbix 密碼并且無法登錄&#xff0c;請聯系您的 Zabbix 管理員。 超級管理員用戶可以更改用戶 配置表單 中所有用戶的密碼。 如果超級管理員忘記了密碼并且無法登錄&#xff0c;則必須運行以下 SQL 查詢…

生成樹、Prime、Kruskal

1、任何一個帶權無向連通圖的最小生成樹——可能是不唯一的。 2、給定有權無向圖的鄰接矩陣如下&#xff0c;其最小生成樹的總權重是&#xff1a;14 3、給定有權無向圖如下。關于其最小生成樹&#xff0c;最小生成樹不唯一&#xff0c;其總權重為23。 4、給出如下圖所示的具有…

用Suno V4.5試了一下1850字的歌詞進行創作出來了6分鐘的歌曲

我的寶貝V1,未來AI視界,5分鐘 之前的Suno 3和Suno 4的版本&#xff0c;創作的音樂最長是4分鐘&#xff0c;這里最大的問題就是&#xff0c;唱到4分鐘歌曲就突然斷了&#xff0c;那么只能使用續寫的方式進行創作。對于續寫的問題&#xff0c;其一增加用戶的使用和理解成本&…

機器人編程基礎---C語言中的表達式和求值

C語言中的表達式和求值 C語言中的表達式和求值表達式示例代碼示例說明C語言中的表達式和求值 表達式是運算符和操作數(變量、常量、表達式等)的組合,它們可以產生一個值。 表達式示例 int x = 10, y = 20; int z = x + y * 2; // 根據運算符優先級,先計算y*2,然后計算x…

[UVM]在SoC中用寄存器模型backdoor訪問寄存器的案例

在SoC中用寄存器模型backdoor訪問寄存器的案例 摘要:在 UVM (Universal Verification Methodology) 驗證環境中,寄存器模型是驗證 DUT (Design Under Test) 寄存器行為的重要工具。特別是對于層次化的驗證環境(如 IP 到 Sub-system 再到 SoC 的集成),使用 UVM 寄存…

NV203NV207SSD固態閃存NV208NV213

NV203NV207SSD固態閃存NV208NV213 美光SSD全解析&#xff1a;NV203/NV207/NV208/NV213技術矩陣 一、產品定位與技術脈絡 在存儲技術迭代浪潮中&#xff0c;美光NV系列產品構建起多層次的技術矩陣。NV203作為入門級SATA SSD&#xff0c;主打成本控制與基礎性能平衡&#xff0c…

迭代器的思想和實現細節

1. 迭代器的本質 迭代器是一種行為類似指針的對象&#xff0c;它可能是指針&#xff08;如 std::vector 的迭代器&#xff09;&#xff0c;也可能是封裝了指針的類&#xff08;如 std::list 的迭代器&#xff09;。如果是指針那天然就可以用下面的運算&#xff0c;如果是類&am…

工業傳動核心部件深度剖析:絲桿升降機與氣缸的技術特性及選型指南

在工業自動化技術飛速發展的當下&#xff0c;絲桿升降機與氣缸作為關鍵的直線傳動部件&#xff0c;廣泛應用于各類機械設備中。對于工程師而言&#xff0c;深入了解它們的技術特性、優缺點及適用場景&#xff0c;是實現高效、精準設備設計的重要前提。本文將從技術原理出發&…

HarmonyOS NEXT——DevEco Studio的使用(還沒寫完)

一、IDE環境的搭建 Windows環境 運行環境要求 為保證DevEco Studio正常運行&#xff0c;建議電腦配置滿足如下要求&#xff1a; 操作系統&#xff1a;Windows10 64位、Windows11 64位 內存&#xff1a;16GB及以上 硬盤&#xff1a;100GB及以上 分辨率&#xff1a;1280*8…

Modbus 通訊協議(超詳細,簡單易懂)

目錄 一、協議中的寄存器定義 二、協議概述 三、使用串口的Modbus 報文幀 ?編輯 3.1、Modbus ASCII 模式 3.2、Modbus RTU 模式 3.3、功能碼概要 3.4、Modbus 報文分析 四、什么是RS-485 RS-232&#xff1f; 一、協議中的寄存器定義 閱讀 Modbus 協議時會發現它的概念別扭…

計算機總線系統入門:理解數據傳輸的核心

一、總線系統簡介&#xff1a;計算機內部的交通網絡 在計算機系統中&#xff0c;總線是指連接各個組件的一組共享信號線或傳輸通道&#xff0c;用于在系統內不同的硬件模塊之間傳遞數據、地址、控制信號等信息。它類似于交通系統中的道路&#xff0c;幫助計算機各個部件&#…

《應用開發突圍指南:敏捷開發的實戰精髓》

如何在應用開發中精準且深入地應用敏捷開發方法呢&#xff1f;讓我們一同深入探索。 敏捷開發&#xff0c;絕非僅僅是一種開發流程&#xff0c;更是一種蘊含深刻智慧的理念與思維方式。它與傳統開發模式有著本質的區別&#xff0c;傳統開發模式如同嚴謹的線性旅程&#xff0c;…

《高性能MySQL》第1講:MySQL架構

MySQL是一個非常流行的關系型數據庫管理系統,它的設計非常靈活,能夠適應多種不同的應用場景。無論是Web應用、數據倉庫,還是高可用性系統,MySQL都能勝任。為了更好地理解MySQL的工作原理,我們需要從它的架構入手。 1.1 MySQL邏輯架構 首先,我們來看一下MySQL的邏輯架構…

數據賦能(212)——質量管理——統一性原則

概述 數據統一性原則在數據管理的各個環節中都具有不可忽視的重要性。它確保了數據在不同部門、系統和時間點上的一致性和可比性&#xff0c;為企業的決策制定、業務分析、風險管理等提供了準確、可靠的數據支持。 原則定義 數據統一性原則&#xff1a;在數據的收集、處理、…