<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+"&nbsp;&nbsp;密码:"+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-本地数据库的操作的更多相关文章

  1. HTML5本地数据库(SQLite)示例

    本文转载自http://blog.sina.com.cn/s/blog_641cf27f01016pm5.html 按照国内一HTML5先行者的例子仿写了一个用HTML5 API来操作本地SQLite ...

  2. HTML5本地数据库(WebSQL)[转]

    除了sessionStorage和localStorage外,HTML5还支持通过本地数据库进行本地数据存储,HTML5采用的是"SQLite"这种文件型数据库,该数据库多集中在嵌 ...

  3. (转)HTML5 本地数据库(SQLite) 示例

      HTML5 本地数据库(SQLite) 示例 2012-05-07 16:21:13 标签:SQLite HTML5本地数据库 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作 ...

  4. html5本地数据库(一)

    本地数据库 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important ...

  5. 【HTML5】HTML5本地数据库(Web Sql Database)

    Web Sql数据库简介 Web SQL数据库API实际上不是HTML5规范的组成部分,而是单独的规范.它通过一套API来操纵客户端的数据库. Web SQL数据库的浏览器支持情况 Web SQL 数 ...

  6. Xamarin.Android 本地数据库 SQLiteDatabase 操作

    目的:使用 SQLiteDatabase 创建本地数据库.表,并对数据进行增删改查操作. 引用命名空间: using Android.App; using Android.Widget; using ...

  7. HTML5本地存储 localStorage操作使用详解

    1.html5几种存储形式 本地存储(localStorage && sessionStorage) 离线缓存(application cache) indexedDB 和 webSQ ...

  8. HTML5 本地数据库(SQLite) 示例

    http://supercharles888.blog.51cto.com/609344/856071 http://www.sqlite.org/download.html

  9. HTML5教程之html 5 本地数据库(Web Sql Database)

    HTML5的Web SQL Databases(html5 本地数据库)的确很诱惑人,当你发现可以用与mysql查询一样的查询语句来操作本地数据库时,你会发现这东西挺有趣的.今天,我们一起来了解HTM ...

  10. Html5 学习系列(六)Html5本地存储和本地数据库

    一个网站如何能在客户的浏览器存储更多的数据呢? 在Html4的时代在浏览器端存储点网站个性化的数据,尤其是用户浏览器的痕迹,用户的相关数据等一般只能存储在Cookie中,但是大多是浏览器对于Cooki ...

随机推荐

  1. 【转】记录PHP、MySQL在高并发场景下产生的一次事故

    看了一篇网友日志,感觉工作中值得借鉴,原文如下: 事故描述 在一次项目中,上线了一新功能之后,陆陆续续的有客服向我们反应,有用户的个别道具数量高达42亿,但是当时一直没有到证据表示这是,确实存在,并且 ...

  2. rust安装

    http://blog.csdn.net/teamlet/article/details/50838996

  3. 【redis】在spring boot2.0中使用redis的StringRedisTemplate 自动注入@Autowired

    1.使用opv.increment 达到增量的效果[判断某个用户 是第几次做这种操作] @RequestMapping("createCode") @RestController ...

  4. iOS中nil、Nil、NULL、NSNull详解

    nil nil 是 ObjC 对象的字面空值,对应 id 类型的对象,或者使用 @interface 声明的 ObjC 对象. 例如: NSString *someString = nil; NSUR ...

  5. [转]SSIS error DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER when connecting to Oracle data source

    本文转自:http://blogs.msdn.com/b/jorgepc/archive/2008/02/12/ssis-error-dts-e-cannotacquireconnectionfrom ...

  6. Linux驱动虚拟地址和物理地址的映射

    一般情况下,Linux系统中,进程的4GB内存空间被划分成为两个部分------用户空间和内核空间,大小分别为0~3G,3~4G. 用户进程通常情况下,只能访问用户空间的虚拟地址,不能访问到内核空间. ...

  7. 大气散射 Aerial Perspective

    http://mathinfo.univ-reims.fr/IMG/pdf/PreethamSig2003CourseNotes.pdf https://blog.csdn.net/toughbro/ ...

  8. TensorFlow------TFRecords的分析与存储实例

    TensorFlow------TFRecords的分析与存储实例: import os import tensorflow as tf # 定义cifar的数据等命令行参数 FLAGS = tf.a ...

  9. pthread_getspecific和pthread_setspecific使用

    pthread_getpecific和pthread_setspecific实现同一个线程中不同函数间共享数据的一种很好的方式. #more test.c /* * ================= ...

  10. [python爬虫] Selenium常见元素定位方法和操作的学习介绍(转载)

    转载地址:[python爬虫] Selenium常见元素定位方法和操作的学习介绍 一. 定位元素方法 官网地址:http://selenium-python.readthedocs.org/locat ...