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> 离线缓存的开启实例使用apache设置 1.apache配置文件搜索Addtype,我的addtype已经存在项目,如下 AddType application/x-compress .Z AddType application/x-gz...
TmodJS是一套完整的前端模块框架。 虽然我们PHP框架自带各种模板引擎,但是始终是后端模板引擎。例如我们在使用ThinkPHP3.2.3中如果是Ajax异步加载页面,拼接HTML真的是很头疼的一件事情。...
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body>...
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>获取mac地址</title> </head&g...
代码1:<!--代码开始--> <script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script> <script>...
工厂模式虽然解决了创建多个对象的问题,但是并没有解决识别对象从属的问题.因为都属于object.因此出现了构造函数//构造函数名称首字母大写是规范 function Box(name,age){ this.name=name; this.age=age; this.run=funct...