html5中sql 使用
来源:互联网 发布:手机网络管理软件 编辑:程序博客网 时间:2024/06/06 12:29
html5中sql 使用
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title></title> <script src="sql.js"></script></head><body onload="init()"> <table> <tr><td>姓名:</td><td><input type="text" id="name"></td></tr> <tr><td>留言:</td><td><input type="text" id="memo"></td></tr> <tr> <td></td> <td><input type="button" value="保存" onclick="saveData()"></td> </tr> </table><hr/><table id="datatable" border="1"></table> <p id="msg"></p></body></html>
js
/** * Created by 宋贤 on 2015/10/15. */var datatable=null;var db=openDatabase("MyData","","My Database",1024*100);function init(){ datatable=document.getElementById("datatable"); showAllData();}function removeAll(){ for(var i=datatable.hasChildNodes.length-1;i>=0;i--){ datatable.removeChild(datatable.childNodes[i]); } var tr=document.createElement("tr"); var th1=document.createElement("th"); var th2=document.createElement("th"); var th3=document.createElement("th"); th1.innerHTML="姓名"; th2.innerHTML="留言"; th3.innerHTML="时间"; tr.appendChild(th1); tr.appendChild(th2); tr.appendChild(th3); datatable.appendChild(tr);}function showData(row){ var tr=document.createElement("tr"); var td1=document.createElement("td"); td1.innerHTML=row.name; var td2=document.createElement("td"); td2.innerHTML=row.message; var td3=document.createElement("td"); var t=new Date(); t.setTime(row.time); td3.innerHTML= t.toLocaleDateString()+" "+ t.toLocaleTimeString(); tr.appendChild(td1); tr.appendChild(td2); tr.appendChild(td3); datatable.appendChild(tr);}function showAllData(){ db.transaction(function(tx){ tx.executeSql("CREATE TABLE IF NOT EXISTS MsgData(name TEXT,message TEXT,time INTEGER)",[]); tx.executeSql("SELECT * FROM MsgData",[],function(tx,rs){ removeAll(); console.log("ss"); for(var i=0;i<rs.rows.length;i++){ showData(rs.rows.item(i)); } }); });}function addData(name,message,time){ db.transaction(function(tx){ tx.executeSql("INSERT INTO MsgData VALUES(?,?,?)",[name,message,time],function(tx,rs){ alert("成功"); },function(tx,error){ alert(error.source+"::"+error.message); }); });}function saveData(){ var name=document.getElementById("name").value; var memo=document.getElementById("memo").value; var time=new Date().getTime(); addData(name,memo,time); showAllData();}
0 0
- html5中sql 使用
- HTML5中FileReader的使用
- HTML5 中 postMessage sendMessage使用
- html5中video的使用
- 在 HTML5 中使用 SVG
- HTML5中canvas的使用
- html5中canvas元素使用
- HTML5中进行SQL的操作
- html5 使用web SQL database简单实例
- HTML5 web SQL 和indexedDB的使用
- html5中如何使用自定义属性
- 关于HTML5中使用地理信息(一)
- 关于HTML5中使用地理信息(二)
- 关于HTML5中使用地理信息(三)
- HTML5中canvas的使用介绍
- HTML5中微数据的使用举例
- 使用node.js中加载cocos2d-html5
- HTML5开发中使用MVC模式
- 第7周项目4-队列数组
- 涂鸦
- linux wake_up
- ZMQ的初步学习
- 条理清晰的搭建SSH环境之整合Struts和Spring
- html5中sql 使用
- 共享一些毕业设计论文
- 众筹出版《介绍用Java编程》一书
- LeetCode解题报告--Swap Nodes in Pairs
- 条理清晰的搭建SSH环境之整合Hibernate和Spring
- uboot 显示nandflash中的图片
- Quarts 示例2
- SQL AUTO INCREMENT 字段 高级教程
- 大数据的排序策略