[英]JavaScript WebSQL databases
I'm having a problem with my code below.我的下面的代码有问题。
db = openDatabase('mydb', '1.0', 'my first database', 5 * 1024 * 1024);
if(!db) { alert("Failed to connect to database."); }
else {
function doQuery(queryType,query) {
function errorHandler(tr, error) {
alert('Oops. Error was: '+error.message+' (Code '+error.code+')');
var we_think_this_error_is_fatal = true;
if (we_think_this_error_is_fatal) return true;
return false;
}
if(queryType == "SELECT") {
function dataHandler(tr, rs) {alert("1")}
db.transaction(function (tr) { tr.executeSql(query,[],dataHandler,errorHandler)})
}
else {
function dataHandler(tr, rs) { alert("2")}
db.transaction(function (tr) { tr.executeSql(query,[],dataHandler,errorHandler)})
}
} // doquery
} // else
db, tables, and records already was inserted, so, then, when im calling it in mypage: db、表和记录已经插入,因此,当我在 mypage 中调用它时:
<td align="right">
<div id="body">
<textarea id="txt" rows="20" cols="48">
</textarea>
</div>
<input type="button" id="button" onClick="doQuery('SELECT',txtarea.value)" value="Execute SQL">
</td>
I'm getting alert(2) instead of alert(1), why?我收到的是 alert(2) 而不是 alert(1),为什么?
txtarea.value
of course, is textarea
object, so whats wrong? txtarea.value
当然是textarea
对象,有什么问题吗?
I would take all the function definitions out of the first else block (get rid of that else).我会从第一个 else 块中取出所有函数定义(去掉 else)。 Change the name of the second dataHandler function to dataHandler2 and see what you get.
将第二个 dataHandler 函数的名称更改为 dataHandler2,看看你得到了什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.