websql使用实例
2024-09-30 02:43:15
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>websql应用</title>
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<input type="text" id="title" />
<textarea name="context" id="context" cols="20" rows="8"></textarea>
<input type="button" value="保存" onclick="save()" />
<input type="button" value="查看" onclick="chakan()" />
<ol id="chakan">
123
</ol>
</body>
<script>
var dbsize=2*1024*1024;
db=openDatabase("todo","","",dbsize);
db.transaction(function(tx){
tx.executeSql("CREATE TABLE IF NOT EXISTS notes (id integer PRIMARY KEY,title char(50),inputMemo text,last_date datetime)");
}
);
function save(){
var title=$("#title").val();
var inputMemo=$("#context").val();
db.transaction(function(tx){
tx.executeSql("INSERT INTO notes (title,inputMemo,last_date) values(?,?,datetime('now','localtime'))",[title,inputMemo]);
});
}
function chakan(){
$("ol").empty();
var note="";
db.transaction(function(tx){
tx.executeSql("SELECT id,title,inputMemo,last_date FROM notes",[],function(tx,result){
if(result.rows.length>0){
for (var i = 0; i <result.rows.length; i++) {
var item=result.rows.item(i);
//console.log(item["inputMemo"]);
note+="<li>"+"<h3>"+item["title"]+"</h3><p>"+item["inputMemo"]+"</p></li>";
}
$("#chakan").append(note);
}}
);
});
}
</script>
</html>
最新文章
- 怎样实现了捕获应用中的日志在android开发中
- [moka同学笔记]yii2 activeForm 表单样式的修改(二)
- pjax 历史管理 jQuery.History.js
- [terry笔记]Flashback
- android.os.DeadObjectException memory near r0: 异常处理 Consumer closed input channel or an error occurred. events=0x9
- HTML+CSS+JS学习总结
- opencv开发的程序分发给客户时所需要的dll文件
- SQL导入
- 手机字段存储报错 :Warning Code : 1264 Out of range value for column &#39;buyer_tpl&#39; at row 1
- centos6 搭建hdwiki
- UE4中FString转UTF8及UTF8转FString
- 关于C#chart图表实现多条折线动态绑定数据的问题
- java反射取private字段
- ios12怎么投屏电脑 苹果手机怎么投
- React Native之FlatList的介绍与使用实例
- kalman filter卡尔曼滤波器- 数学推导和原理理解-----网上讲的比较好的kalman filter和整理、将预测值和观测值融和
- CSS----布局注意事项
- Link Cut Tree 总结
- CubieTruck入手第一天
- java克隆机制
热门文章
- Failed to configure a DataSource: &#39;url&#39; attribute is not specified and no embedded datasource could be configured.Reason: Failed to determine a suitable driver class
- Python数据结构和类型--解压序列赋值多个变量
- 洛谷 p1141 01迷宫题解
- PAT (Advanced Level) Practise - 1099. Build A Binary Search Tree (30)
- 用事件队列解决GUI的操作顺序问题(Qt中处理方法)
- Dubbo中的监控和管理
- Bootstrap 原始按钮
- C++系统学习之六:函数
- Ubuntu18.04 下联想电脑 无法连接WIFI问题解决
- Mac OSX: 有线共享WiFi