使用环境:Chrome 36.0...+

技术:HTML5

目的:习练HTML5

功能概述:记录管理每天工作内容,便签清单

HTML5+CSS3呈现UI,JavaScript操作数据库,SQLite存储数据

预览:

关键代码:

             // save data
function dataStorage(o) { for (var i = 0; i < o.childNodes.length; i++) {
if (o.childNodes[i].nodeName == "P") {
o.removeChild(o.childNodes[i]);
}
} if (o.innerText.replace(/\s+/g, "").length == 0) {
return;
} var task = new Object();
task.task = o.innerText;
task.progressid = 2;
task.progress = ProgressEnum[task.progressid];
if (o.id == "newEditNode") {
o.removeAttribute("id");
task.year = nowDate.getFullYear();
task.month = nowDate.getMonth() + 1;
task.day = nowDate.getDate(); // open a database transaction
DB.transaction(function(tx) {
// insert into table(task,progress,year,month,day)
tx.executeSql('INSERT INTO ' + TableName + ' VALUES(?,?,?,?,?,?,0)', [task.task, task.progress, task.progressid, task.year, task.month, task.day],
// success:show success log in console
function(tx, rs) {
queryData(o.parentElement.id);
console.log("save data successfully!");
},
// fail:show error log in console
function(tx, error) {
console.log(error.source + "::" + error.message);
});
});
} else {
DB.transaction(function(tx) {
// update
tx.executeSql('UPDATE ' + TableName + ' SET task=? WHERE rowid=?', [task.task, o.id],
// success:show success log in console
function(tx, rs) {
queryData(o.parentElement.id);
console.log("update data successfully!");
},
// fail:show error log in console
function(tx, error) {
console.log(error.source + "::" + error.message);
});
});
}
} // query data
function queryData(parentId) {
document.getElementById(parentId).innerHTML = "";
DB.transaction(function(tx) {
tx.executeSql('SELECT rowid,* FROM ' + TableName + ' WHERE enabled=0 ORDER BY progressid ASC, rowid DESC', [], function(tx, rs) {
for (var i = 0; i < rs.rows.length; i++) {
createNode(rs.rows.item(i), parentId); //create node to show data
}
});
});
createEditNode(parentId); // create new edit node
} //change current date
function changeDate(cid, m) {
nowDate = new Date(document.getElementById(cid).innerText);
if (m == "+") {
nowDate.setDate(nowDate.getDate() + 1);
} else {
nowDate.setDate(nowDate.getDate() - 1);
}
document.getElementById("currentDate").innerText = nowDate.getFullYear() + "." + (nowDate.getMonth() + 1) + "." + nowDate.getDate();
TableName = "doList" + nowDate.getFullYear() + (nowDate.getMonth() + 1) + nowDate.getDate();
DB.transaction(function(tx) {
//create data table
tx.executeSql('CREATE TABLE IF NOT EXISTS ' + TableName + '(task TEXT,progress varchar(300),progressid INTEGER,year INTEGER,month INTEGER,day INTEGER,enabled INTEGER)', []);
});
queryData("divcontent");
} function load() {
if (navigator.appCodeName != "Mozilla") { } else {
/* ---- start program --- */
// create database
nowDate = new Date();
ProgressEnum = ["Executing", "Reform", "Pending", "Finished", "Cancel"];
TableName = "doList" + nowDate.getFullYear() + (nowDate.getMonth() + 1) + nowDate.getDate();
document.getElementById("currentDate").innerText = nowDate.getFullYear() + "." + (nowDate.getMonth() + 1) + "." + nowDate.getDate();
DB = openDatabase("toDoList", '', 'To Do list DataBase', 102400);
DB.transaction(function(tx) {
//create data table
tx.executeSql('CREATE TABLE IF NOT EXISTS ' + TableName + '(task TEXT,progress varchar(300),progressid INTEGER,year INTEGER,month INTEGER,day INTEGER,enabled INTEGER)', []);
});
queryData("divcontent");
}
}

URL:http://dicolancy.github.io/DemoCode/html5/todolist_chrome.html

最新文章

  1. 微信小程序
  2. 面积(area)
  3. eclipse工程加入jquery.min.js报错:missing semicolon
  4. IIS SMTP status codes
  5. 使用Windows Azure创建Linux系统虚拟机-下
  6. java提高篇(十)-----详解匿名内部类 ,形参为什么要用final
  7. css 权威指南笔记(四)选择器
  8. mssql 判断sql语句的执行效率语句
  9. Ext.net.DirectMethods
  10. 使用apache daemon让java程序在unix系统上以服务方式运行
  11. 输入和输出--javase中的路径
  12. bzoj 1814 Ural 1519 Formula 1 插头DP
  13. 深入理解CoordinatorLayout.Behavior
  14. 加载静态界面----,要不要会加载cookie和页面参数
  15. mybatis查询修改同时操作
  16. .NET Core 2.0应用程序大小减少50%
  17. Android强制关闭某个指定应用 “关闭应用”
  18. 括弧匹配检验(check.cpp)
  19. Eclipse中GitLab的配置和使用入门
  20. Discuz常见小问题-如何关闭验证码

热门文章

  1. C# task和timer实现定时操作
  2. JVM垃圾收集器(1)
  3. “全栈2019”Java异常第一章:什么是异常?
  4. git 使用merge 对本地分支进行合并 并进行代码提交的流程
  5. Vulnhub Billu_b0x
  6. jdk1.6 支持 tls1.2协议 并忽略身份验证
  7. JAVA数组的定义方式
  8. 解决 MySQL 1045错误的三种方法 (转)
  9. IECapt、CutyCapt 生成网页快照
  10. (转)Javascript模块化编程(三):Require.js的用法