关于websql查找返回值的问题

小弟想对websql进行简单的封装,然而select取值的时候返回值不知道如何取出来,求各位大神指点迷津。代码如下:
图片说明
<!DOCTYPE html>




<pre><code> var db = openDatabase(&#39;mydb&#39;, &#39;1.0&#39;, &#39;mydbname&#39;, 2097152); function query(sql){ db.transaction(function (tx) { tx.executeSql(sql); }); } function select(sql) { var sql1 = sql; db.transaction(function (tx,sql) { //创建表外面用双引号 tx.executeSql(sql1, [], function (a, results) { console.log(results) result = results; }) }); } var result = []; function selectall() { db.transaction(function (tx) { //创建表外面用双引号 tx.executeSql(&quot;select * from role&quot;, [], function (a, results) { for (i = 0; i &lt; results.rows.length; i++){ var what = results.rows.item(i); result.push(what); } console.log(result); }); }); console.log(result); return result; } &lt;/script&gt; </code></pre> <p></head><br> <body></p> <script> query("CREATE TABLE IF NOT EXISTS role ('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,'name' TEXT,'hobby' TEXT,date timestamp not null default (datetime('now','localtime')))") query("insert into role(name,hobby) values('gouzi','wanshe')"); query("insert into role(name,hobby) values('gouzi','wanshe')"); console.log(selectall()); query("drop table if exists role");


Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐