db.transaction(createSheetDB,function(){alert("Sheet creation error!")},function(){alert("Sheet created!")});
函数createSheetDB是一个回调函数,由db.transaction()隐式调用,它也传递一个参数tx.我已经实现了这样的函数createSheetDB(tx):
function createSheetDB(tx) {
var nextId = getNextId();
tx.executesql("INSERT INTO SHEET(id,name,desc) VALUES("+nextId+",'"+sheetName+"','"+desc+"')",[],function(){alert("Sheet row inserted!")},function(tx,err){alert("Sheet row insertion Error: "+err.message+" "+err.code)}
);}
最佳答案
您可以使用一种技术创建一个新的回调,该回调将关闭您想要的变量.
@H_403_30@function doStuff(callback) {
var val = 43;
callback(val);
}
function myCallback(val,anotherVal) {
alert("val: " + val + "\nanotherVal: " + anotherVal);
}
(function() {
var anotherVal = "Whoa!",anotherCallback = function(val) {
return myCallback(val,anotherVal);
};
doStuff(anotherCallback);
}());