WebSql的原理是浏览器集成了sqllite数据库,Js操作,浏览器协助完成,没有多复杂。
<!--
三个核心方法
openDatabase:这个方法使用现有数据库或创建新的数据库
transaction:这个方法允许我们根据情况控制事务提交或者回滚
executeSql:执行sql查询
应用:离线词典
-->
<script>
//检测浏览器是否支持websql
if(window.openDatabase){
//创建或者使用数据库
var conn=openDatabase('think-shop','1.0',1024*1024,function(){});
//控制事务控制提交或者回滚
conn.transaction(function(fx){
/*
//1.执行sql,创建表结构
fx.executeSql(
"create table member(id int,name varchar)",
[],
function(){
//成功自动执行
console.log('创建成功!');
},
function(){
//失败自动执行
console.log('创建失败!');
}
);
*/
/*
//2.执行sql,新增数据到表
fx.executeSql(
"insert into member(id,name) values(?,?)",
[1,'张三'],
function(){
//成功自动执行
console.log('新增成功!');
},
function(){
//失败自动执行
console.log('新增失败!');
}
);
*/
/*
//3.执行sql,更新数据
fx.executeSql(
"update member set name=? where id=?",
['李四',1],
function(){
//成功自动执行
console.log('修改成功!');
},
function(){
//失败自动执行
console.log('修改失败!');
}
);
*/
/*
//4.执行sql,查询数据
fx.executeSql(
"select * from member where id=?",
[1],
function(fx,result){
//成功自动执行
console.log('查询成功!数据如下:');
console.log(result);
},
function(){
//失败自动执行
console.log('查询失败!');
}
);
*/
//5.执行sql,删除数据
fx.executeSql(
"delete from member where id=?",
[1],
function(fx,result){
//成功自动执行
console.log('删除成功!数据如下:');
console.log(result);
},
function(){
//失败自动执行
console.log('删除失败!');
}
);
});
}
else{
console.log('浏览器不支持!');
}
</script> 捕捉模式从DOM最顶层一直到最后一层,冒泡正好相反,具体运行以下实例测试.<!DOCTYPE html> <html> <head> <title>捕捉和冒泡</title> <meta charset="...
https://3gimg.qq.com/lightmap/v1/marker/index.html?marker=coord:37.6767600000,112.7297800000&key=TKUBZ-D24AF-GJ4JY-JDVM2-IBYKK-KEBCU&referer=p...
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <script type...
二期项目中生成的简历二维码是使用canvs生成的,微信浏览器中不能识别二维码,只能扫码。懒的换phpqrcode,于是转canvs。//设置一个url var url = "{yun:}$config.sy_weburl{/yun}/mingli/index....
工厂模式虽然解决了创建多个对象的问题,但是并没有解决识别对象从属的问题.因为都属于object.因此出现了构造函数//构造函数名称首字母大写是规范 function Box(name,age){ this.name=name; this.age=age; this.run=funct...
//构造函数 function Box(name,age){ this.name=name; this.age=age; this.run=function(){ return this.name+'--'+this.age; } } var&nbs...