


How does the web front end update the cache? Singleton mode encapsulates opendatabase
The content of this article is about how to update the cache on the web front-end? The singleton mode encapsulates opendatabase and has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
If you don’t understand the operation of the opendatabase database, it is recommended that you first study the previous article "Web Front-end Cache Four Opendatabase" and then look at the content of this article. The content of this chapter is also the last in the front-end cache series. A simple encapsulation of the opendatabase database. Of course, for those with Java background, you can ignore this article.
Okay, let’s not talk nonsense and go straight to the topic. Please read the text (still based on the example of the previous article):
nbsp;html> <meta> <title>Title</title> <!-- openDatabase与android里面的sqlite差不多 最好的选型存储 --> <h1 id="opendatabse数据库操作">opendatabse数据库操作</h1> <button>创建user数据表</button> <button>插入数据</button> <button>查询数据</button> <button>修改数据</button> <button>删除数据</button> <button>删除user数据表</button> <script> let findId = id => document.getElementById(id); //模拟一条user数据 let user = { username: "liuqiang", password: "123569874", info: "beaconApp开发团队中一员" }; /** * 创建数据库 或者此数据库已经存在 那么就是打开数据库 * name: 数据库名称 * version: 版本号 * displayName: 对数据库的描述 * estimatedSize: 设置数据的大小 * creationCallback: 回调函数(可省略) */ let db = openDatabase("MySql", "1.0", "我的数据库描述", 1024 * 1024); let result = db ? "数据库创建成功" : "数据库创建失败"; console.log(result); const USER_TABLE_SQL = "create table if not exists userTable (id integer primary key autoincrement,username varchar(12)," + "password varchar(16),info text)"; const INSERT_USER_SQL = "insert into userTable (username, password,info) values(?,?,?)"; const QUERY_USER_SQL = "select * from userTable"; const UPDATE_USER_SQL = "update userTable set password = ? where username = ?"; const DELETE_USER_SQL = "delete from userTable where username = ?"; const DROP_USER_SQL = "drop table userTable"; /** * 封装数据库工具类 */ class DatabaseUtil { /** * 构造方法 * @param sqlSentence 数据库语句 * @param params 数据库操作的参数 */ constructor(sqlSentence, ...params) { this.sqlSentence = sqlSentence; this.params = params; } //获取当前实例 static getInstance(sqlSentence, ...params) { return new DatabaseUtil(sqlSentence, ...params) } /** * 执行数据库操作 * @param callback 成功的回调 * @param errorCallback 失败的回调 */ execute(callback, errorCallback) { db.transaction(tx => { tx.executeSql(this.sqlSentence, this.params, callback, errorCallback) }) } } /** * 点击事件 增删查改 */ let btnCreate = findId("btn-create"); let btnInsert = findId("btn-insert"); let btnQuery = findId("btn-query"); let btnUpdate = findId("btn-update"); let btnDelete = findId("btn-delete"); let btnDrop = findId("btn-drop"); //创建数据表 btnCreate.onclick = () => DatabaseUtil.getInstance(USER_TABLE_SQL) .execute(function (transaction, resultSet) { alert('创建user表成功:' + result); }, function (transaction, error) { alert('创建user表失败:' + error.message); }); //插入数据 btnInsert.onclick = () => DatabaseUtil.getInstance(INSERT_USER_SQL, user.username, user.password, user.info) .execute(function (transaction, resultSet) { alert("添加数据成功") }, function (transaction, error) { alert("添加数据失败:" + error.message) }); //查询数据 btnQuery.onclick = () => DatabaseUtil.getInstance(QUERY_USER_SQL) .execute(function (transaction, resultSet) { console.log(resultSet); }, function (transaction, error) { alert("查询失败:" + error.message) }); //修改数据 btnUpdate.onclick = () => { user.password = "111666666";//修改密码 DatabaseUtil.getInstance(UPDATE_USER_SQL, user.password, user.username) .execute(function (transaction, resultSet) { alert("修改数据成功") }, function (transaction, error) { alert("修改数据失败:" + error.message) }) }; //删除数据 btnDelete.onclick = () => DatabaseUtil.getInstance(DELETE_USER_SQL, user.username) .execute(function (transaction, resultSet) { alert("删除数据成功") }, function (transaction, error) { alert("删除数据失败:" + error.message) }); //删除数据表 btnDrop.onclick = () => DatabaseUtil.getInstance(DROP_USER_SQL) .execute(function (transaction, resultSet) { alert("删除数据表成功") }, function (transaction, error) { alert("删除数据表失败:" + error.message) }); </script>
The above is how to update the web front-end cache? The singleton mode encapsulates the full introduction of opendatabase. If you want to know more about HTML video tutorial, please pay attention to the PHP Chinese website.
The above is the detailed content of How does the web front end update the cache? Singleton mode encapsulates opendatabase. For more information, please follow other related articles on the PHP Chinese website!

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Notepad++7.3.1
Easy-to-use and free code editor

Atom editor mac version download
The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.