html5-本地数据库的操作
<script src="jquery-1.8.3.js"></script>
<script>
/* IE11不支持此操作
创建数据库
解释一下openDatabase方法打开一个已经存在的数据库,如果数据库不存在,它还可以创建数据库。几个参数意义分别是:
1,数据库名称。
2,版本号 目前为1.0,不管他,写死就OK。
3,对数据库的描述。
4,设置数据的大小。
5,回调函数(可省略)。
*/
var db=openDatabase("myDB","1.0","testDB",1024*1024,function(){});
//添加
function add()
{
var username=$("#username").val();
var pwd=$("#pwd").val();
//transaction:这个方法允许我们根据情况控制事务提交或回滚。
db.transaction(function(fx){
//executeSql执行SQL语句创建表,并新建字段
fx.executeSql("create table if not exists UserInfo(UserName TEXT,Pwd TEXT)",[]);
fx.executeSql("insert into UserInfo values(?,?)",[username,pwd],function(){
alert("添加成功")
},function(){
alert("添加失败");
})
})
}
//获取
function get()
{
var username=$("#username").val();
db.transaction(function(fx){
//也可以用select * from UserInfo where UserName='"+username+"'
fx.executeSql("select * from UserInfo where UserName=?",[username],function(fx,rs){
if(rs)
{
for(var i=0;i<rs.rows.length;i++)
{
var str="<p>用户名:"+rs.rows.item(i).UserName+" 密码:"+rs.rows.item(i).Pwd+"</p>";
$("#content").append(str);
}
}
});
})
}
//删除
function del()
{
var username=$("#username").val();
db.transaction(function(fx){
fx.executeSql("delete from UserInfo where UserName=?",[username],function(fx,rs){
alert("删除成功");
get();
});
})
}
</script>
<body>
<input type="text" id="username">
<input type="text" id="pwd">
<input type="button" onClick="add()" value="添加">
<input type="button" onClick="get()" value="获取">
<input type="button" onClick="del()" value="删除">
<div id="content"></div>
html5-本地数据库的操作的更多相关文章
- HTML5本地数据库(SQLite)示例
本文转载自http://blog.sina.com.cn/s/blog_641cf27f01016pm5.html 按照国内一HTML5先行者的例子仿写了一个用HTML5 API来操作本地SQLite ...
- HTML5本地数据库(WebSQL)[转]
除了sessionStorage和localStorage外,HTML5还支持通过本地数据库进行本地数据存储,HTML5采用的是"SQLite"这种文件型数据库,该数据库多集中在嵌 ...
- (转)HTML5 本地数据库(SQLite) 示例
HTML5 本地数据库(SQLite) 示例 2012-05-07 16:21:13 标签:SQLite HTML5本地数据库 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作 ...
- html5本地数据库(一)
本地数据库 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important ...
- 【HTML5】HTML5本地数据库(Web Sql Database)
Web Sql数据库简介 Web SQL数据库API实际上不是HTML5规范的组成部分,而是单独的规范.它通过一套API来操纵客户端的数据库. Web SQL数据库的浏览器支持情况 Web SQL 数 ...
- Xamarin.Android 本地数据库 SQLiteDatabase 操作
目的:使用 SQLiteDatabase 创建本地数据库.表,并对数据进行增删改查操作. 引用命名空间: using Android.App; using Android.Widget; using ...
- HTML5本地存储 localStorage操作使用详解
1.html5几种存储形式 本地存储(localStorage && sessionStorage) 离线缓存(application cache) indexedDB 和 webSQ ...
- HTML5 本地数据库(SQLite) 示例
http://supercharles888.blog.51cto.com/609344/856071 http://www.sqlite.org/download.html
- HTML5教程之html 5 本地数据库(Web Sql Database)
HTML5的Web SQL Databases(html5 本地数据库)的确很诱惑人,当你发现可以用与mysql查询一样的查询语句来操作本地数据库时,你会发现这东西挺有趣的.今天,我们一起来了解HTM ...
- Html5 学习系列(六)Html5本地存储和本地数据库
一个网站如何能在客户的浏览器存储更多的数据呢? 在Html4的时代在浏览器端存储点网站个性化的数据,尤其是用户浏览器的痕迹,用户的相关数据等一般只能存储在Cookie中,但是大多是浏览器对于Cooki ...
随机推荐
- [转]web.xml中webAppRootKey
web.xml中webAppRootKey ------------------------------------------------------------------------------ ...
- XCode6 ,iOS之PCH文件配置
1: 创建PCH文件 NewFile-->Other中的PCH File-->Next-->Create 2:配置PCH文件 项目中的TARGETS-->Build Setti ...
- PHP5.3配置文件php.ini-development和php.ini-production的区别
PHP5.3版本中出现了php.ini-developmen和php.ini-production PHP配置文件与PHP5.2版本相比,命名发生了变化: php.ini-production 对应于 ...
- delphi AlphaControls
http://blog.csdn.net/akof1314/article/details/7076804
- THttpClientSocket token验证
THttpClientSocket uses SynCrtSock非WINHTTP.DLL里面的控件,可以用于手机端. function Client(const SQL: RawUTF8): Raw ...
- windows2012 IIS部署GeoTrust证书踩过的坑。
系统:windows2012 环境:IIS8 在阿里云上买了GeoTrust证书, 按照说明下载证书到服务器, 导入证书, 给IIS站点部署https. 阿里云部署帮助文档:https://help ...
- 创建maven web项目无法创建sec目录
创建maven web项目无法创建sec目录 解决方法:-DarchetypeCatalog=internal
- [转]Configure logging in SSIS packages
本文转自:http://learnsqlwithbru.com/2009/11/26/configure-logging-in-ssis-packages/ n this article we wil ...
- [转] SQL Server 批量 停用/启用 外键约束
本文转自:http://hi.baidu.com/wangzhiqing999/item/ca699308de4f1ff9a1103429 今天百度知道上面,看到这样一个要求: 现在有一个库,有很多张 ...
- iOS: 常用的宏
Github地址:https://github.com/XFZLDXF/Macro/blob/master/MacroDefinition.h // // MacroDefinition.h // M ...