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> 由于工作需要长期使用Ajax,一个页面重复的AJAX请求太多,于是封装起来,只需要编写回调函数/* ------------- 使用方法: 1.ajaxrequest()函数执行准备的参数(1.请求地址2.发送数据字符串拼接3.type值可选get/post4.回调函数名称) exam...
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> </head> <body>...
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <script type...
维护老项目中客户提到一个页面中有6个表单以上,导致每次保存一个其他的数据全部丢失,自己比较懒没有全部更换为ajax.用户每次输入完成或者选择完成记录cookie,每次提交后加载页面完成初始化cookie即可。以下代码取自w3school比较完善,之前在其他博客使用的经常出现bug,这个比较推荐使用:...
//原型的缺点 function Box(){} Box.prototype={ 'name':'gao', age:23, family:['哥哥','姐姐','妹妹'], &...