WebSql本地存储-1009

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>WebSql本地存储练习</title>


</head>
<body>
<div id="div1">



</div>



</body>
<script src="js/vue.js"></script>
<script>





    var localdb1=window.openDatabase("mystore.db","1.0","mydb1",20000);

    // _id INTEGER PRIMARY KEY AUTOINCREMENT,
    localdb1.transaction(function (tr){
        // tr.executeSql("create table goods(_id  INTEGER PRIMARY KEY AUTOINCREMENT,name text,age Integer)");

        // _id  INTEGER PRIMARY KEY AUTOINCREMENT,

        tr.executeSql("create table goods2(name text,price Number)");

    });

    localdb1.transaction(function (tr) {
        // tr.executeSql("insert into goods(name,age) values (?,?)",["赵6","20"]);

        tr.executeSql("insert into goods2(name,price) values (?,?)",["华为P20","2399.99"]);
    });


    localdb1.transaction(function (tr) {
        tr.executeSql("delete from goods2 where _id=2");
    });


    localdb1.transaction(function (tr) {
       tr.executeSql("update goods2 set name='赵二狗' where _id=1 ")
    });

    localdb1.transaction(function (tr) {
        tr.executeSql("select * from goods2 ",[],
            function (tr,resultSet) {
                for (var i=0;i<resultSet.rows.length;i++){

                    document.write(resultSet.rows.item(i)["_id"]+".");

                    document.write(resultSet.rows.item(i)["name"]);
                    document.write("&nbsp;");
                    document.write(resultSet.rows.item(i)["price"]);
                    document.write("<br>");
                }

            },
            function (tr,error) {
                alert("失败!");
            }
        )

    });






    var v1=  new Vue({
        el:'#div1',
        data: [],

        methods:{
            fn1:function(){
                console.log("fn1,clicked!");
                alert(this.message);
            },

            fn2:function(msg){
                console.log("传入的参数是:"+ msg);
                alert("传入的参数是:"+ msg);
            },


            createPerson: function(){
                this.people.push(this.newPerson);
                // 添加完newPerson对象后,重置newPerson对象
                this.newPerson = {name: '', age: 0, sex: 'Male'}
            },
            deletePerson: function(index){
                // 删一个数组元素
                this.people.splice(index,1);
            },





        }

    });




</script>
</html>

 

 

 

 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
   <style>
      input{
         margin: 5px;
      }
   </style>

</head>

<body>
<input type="text" /><br/>
<input type="button" value="存储数据" />
<input type="button" value="获取数据" />
<input type="button" value="删除数据" />
</body>

<script>

window.onload = function(){
   var aInput = document.getElementsByTagName('input');

   aInput[1].onclick = function(){

      window.localStorage.setItem('name',aInput[0].value);

   };
   aInput[2].onclick = function(){

      alert(window.localStorage.getItem('name'));

   };
   aInput[3].onclick = function(){
      window.localStorage.removeItem('name');

   };
   
   window.addEventListener('storage',function(ev){  //当前页面的事件不会触发
      alert(123);

      console.log( ev.key );
      console.log( ev.newValue );
      console.log( ev.oldValue );
      console.log( ev.storageArea );
      console.log( ev.url );

   },false);
   
};

</script>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值