html5离线记事本
这是一个笔记应用,不需要联网,也不需要数据库,可以直接把数据储存在本地.方便易用! ^_^
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>记事本</title>
- <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
- <style>
- *{ margin: 0; padding: 0; box-sizing: border-box; font-family: 'Microsoft Yahei'; font-size: 14px; box-sizing: border-box;}
- h1{text-align: center; font-size: 26px; line-height: 60px;color: #ff8140;}
- .main{margin: 10px auto;width: 1000px; overflow: hidden; height: 500px;padding: 1%;border: 1px solid #ddd; border-radius: 5px;}
- input{ width: 92%; padding: 5px; outline: none;border: 1px solid #eee;}
- textarea{ width: 100%; overflow: hidden; padding: 5px; outline: none; resize:none; }
- textarea:focus,input:focus { border-color: #f77c3d; }
- .write{padding: 10px; border-radius: 3px; background: #eee; overflow: hidden; float: left;width: 48%;}
- .send{ background: #ff8140; border: 1px solid #f77c3d; color: #fff; box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.25);
- width: 80px; height: 30px; text-align: center; line-height: 30px; border-radius: 3px; float: right; cursor: pointer; }
- .list{padding: 10px; float: left;width: 50%;}
- .item{padding: 10px;border: 1px solid #eee;border-radius: 3px;margin-bottom: 10px;}
- .item .content{padding: 20px 10px;word-break:break-all;background: #fff; display: none;}
- .title{padding-bottom: 5px;border-bottom: 1px solid #eee;cursor: pointer;}
- .title span{color: #999; font-size: 12px;float: right;}
- #noteList{overflow-y: scroll;height: 350px;box-shadow: 0 0 3px #ddd;}
- </style>
- </head>
- <body>
- <h1>记事本</h1>
- <div class="main">
- <div class="write" id="write">
- 标题: <input id="title" type="text" placeholder="请输入标题"><br><br>
- 分类: <select id="type">
- <option value="默认" selected>-请选择-</option>
- <option value="美食">美食</option>
- <option value="代码">代码</option>
- <option value="生活">生活</option>
- </select>
- <br><br>
- <textarea name="" id="cont" cols="30" rows="10" placeholder="今天想说点啥..."></textarea>
- <div class="send" id="add">添加</div>
- </div>
- <div class="list" id="list">
- 标题: <input id="title1" type="text" placeholder="查询标题"><br><br>
- 分类: <select id="type1">
- <option value="默认" selected>-请选择-</option>
- <option value="美食">美食</option>
- <option value="代码">代码</option>
- <option value="生活">生活</option>
- </select>
- <div id="search" class="send">查询</div><br><br>
- <div id="noteList"></div>
- </div>
- </div>
- <script type="template" id="temp">
- <div class="item">
- <div class="title">@title<span>@type: @date</span></div>
- <div class="content">@cont</div>
- </div>
- </script>
- <script>
- $(function(){
- var init = {title:'这是标题',
- date:new Date().toLocaleString(),
- type:'示例',
- cont:'这是一个笔记应用,不需要联网,也不需要数据库,可以直接把数据储存在本地.方便易用!^_^'};
- function show(notes){
- var temp = $('#temp').html();
- var tempStr= '';
- //如果不是数组,变成数组
- if(!Array.isArray(notes)){
- notes = [notes];
- }
- for(var i=notes.length-1;i>-1;i--){
- var note = notes[i];
- tempStr += temp.replace('@title',note.title)
- .replace('@date',note.date)
- .replace('@type',note.type)
- .replace('@cont',note.cont);
- }
- $('#noteList').html(tempStr);
- }
- //读取所有数据
- function showList(){
- var notes = localStorage.getItem('notes');
- if(!notes){
- show(init);
- }else{
- notes = JSON.parse(notes);
- show(notes);
- }
- //第一个展开
- $('#noteList .item:first').find('.title').trigger('click');
- }
- $('#add').click(function(){
- var title = $('#title').val();
- var cont = $('#cont').val();
- var type = $('#type').val();
- if(title == ''){
- alert('标题不能为空!');
- return;
- }
- var data = {title:title,cont:cont,type:type,date:new Date().toLocaleString()};
- var notes = localStorage.getItem('notes');
- if(!notes){
- notes = [];
- }else{
- notes = JSON.parse(notes);
- }
- notes.push(data);
- localStorage.setItem('notes',JSON.stringify(notes));
- showList();
- });
- $('#search').click(function(){
- var title = $('#title1').val();
- var type = $('#type1').val();
- var notes = localStorage.getItem('notes');
- if(!notes){
- alert('没有本地笔记数据!');
- return;
- }else{
- notes = JSON.parse(notes);
- }
- var note = [];
- for(var i=0;i<notes.length;i++){
- //notes[i] json对象
- var flag = false;
- if(!title){
- flag = notes[i].type==type;
- }else if(!type){
- flag = notes[i].title.indexOf(title)>-1;
- }else{
- flag = notes[i].title.indexOf(title)>-1 && notes[i].type==type;
- }
- if(flag){
- note.push(notes[i]);
- }
- }
- if(note.length == 0){
- alert('抱歉~没有对应的笔记!');
- }else{
- show(note);
- }
- });
- $('body').on('click','#noteList .title', function(){
- $(this).next().slideToggle();
- });
- showList();
- })
- </script>
- </body>
- </html>
html5离线记事本的更多相关文章
- 1分钟快速制作漂亮的Html5本地记事本
大家好,以前给大家分享过一个五步骤制作精美的HTML5时钟的文章,点击回顾<五步教你制作漂亮精致的HTML时钟>,还有<一分钟教你如何实现唯美的文字描边>:今天给大家分享一个用 ...
- HTML5离线缓存(Application Cache)
HTML5离线缓存又名Application Cache,是从浏览器的缓存中分出来的一块缓存区,要想在这个缓存中保存数据,可以使用一个描述文件(manifest file),列出要下载和缓存的资源. ...
- HTML5 离线缓存管理库
一.HTML5离线缓存技术 支持离线缓存是HTML5中的一个重点,离线缓存就是让用户即使在断网的情况下依然可以正常的运行应用.传统的本地存储数据的方式有 localstorage,sessionsto ...
- HTML5离线Web应用实战:五步创建成功
[IT168 技术]HTML5近十年来发展得如火如荼,在HTML 5平台上,视频,音频,图象,动画,以及同电脑的交互都被标准化.HTML功能越来越丰富,支持图片上传拖拽.支持localstorage. ...
- 吓哭原生App的HTML5离线存储技术,却出乎意料的容易!【低调转载】
吓哭原生App的HTML5离线存储技术,却出乎意料的容易![WeX5低调转载] 2015-11-16 lakb248 起步软件 近几天,WeX5小编编跟部分移动应用从业人士聊了聊,很多已经准备好全面拥 ...
- html5 离线存储
在html页面中引入manifest文件 <html manifest="sample.appcache"> 在服务器添加mime-type text/cache-ma ...
- HTML5离线缓存问题
HTML5离线缓存问题 1.应用程序缓存 什么是应用程序缓存(Application Cache)? HTML5 引入了应用程序缓存,这意味着 web 应用可进行缓存,并可在没有因特网连接时进行访问. ...
- Manifesto – HTML5 离线应用程序缓存校验工具
Manifesto 是一个 HTML5 离线应用程序缓存校验工具,提供了快速校验 HTML5 manifest 文件有效性的方法.离线应用程序缓存在使用中最困难的部分之一就是无法正常工作的时候没有明显 ...
- HTML5离线存储原理
找到一篇介绍离线缓存的,感觉比之前看到的解释的更透彻,新的知识点记录如下: 大家都知道Web App是通过浏览器来访问的,所以离线状态下是无法使用app的.其中web app中的一些资源并不经常改变, ...
随机推荐
- 2017-12-14python全栈9期第一天第八节之循环语句while
12,while. while 条件: 循环体 无限循环. 终止循环:1,改变条件,使其不成立. 2,break continue
- Tensorflow object detection API 搭建物体识别模型(三)
三.模型训练 1)错误一: 在桌面的目标检测文件夹中打开cmd,即在路径中输入cmd后按Enter键运行.在cmd中运行命令: python /your_path/models-master/rese ...
- docker-compose 案例
官网示例: 安装wordpress version: " services: db: image: mysql:5.7 volumes: - db_data:/var/lib/mysql r ...
- C++ 二维数组作为形参传递使用实例
在线代码编辑器: http://codepad.org/ 1.*指针 void display(int *arr, const int row, const int col) { ; i < r ...
- Hive记录-Impala jdbc连接hive和kudu参考
1.配置环境Eclipse和JDK 2.加载hive jar包或者impala jar包 备注:从CDH集群里面拷贝出来 下载地址:https://www.cloudera.com/downloads ...
- ifconfig: command not found(CentOS 7,其他的可以参考)
ifconfig: command not found 查看path配置(echo相当于c中的printf,C#中的Console.WriteLine) 1 echo $PATH 解决方案1:先看看是 ...
- 我手机上常用的app和常访问的网站
====常用======Opera Mini browser 浏览器(版本26.0.2254.117241以上) 老版本7.7最最经典, 但该版本在新的安卓手机上总有部分区域显示空白. 现在的 Ope ...
- 经典文摘:饿了么的 PWA 升级实践(结合Vue.js)
自 Vue.js 官方推特第一次公开到现在,我们就一直在进行着将饿了么移动端网站升级为 Progressive Web App 的工作.直到近日在 Google I/O 2017 上登台亮相,才终于算 ...
- git 完全讲解 无废话,包含在myeclipse中使用,包括解决冲突
Git 1. Git简介 1.1 git是什么 1.1.1概念 Git:git是一款开源的分布式的版本控制软件 Github:是一个基于git的面向开源及私有软件项目的托管平台 因仅支持git 作为唯 ...
- GCC编译器原理(二)------编译原理一:ELF文件(2)
四. ELF 文件格式分析 ELF文件(目标文件)格式主要四种: 可重定向文件: 文件保存着代码和适当的数据,用来和其他的目标文件一起来创建一个可执行文件或者是一个共享目标文件.(目标文件或者静态库文 ...