dollcrusader
dollcrusader
2017-10-26 01:13

关于websql查找返回值的问题

  • html5
  • javascript
  • sql

小弟想对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");


  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

0条回答

为你推荐