0

如何将值从 javascript var 传递给 executeSql?

我写了这段代码:

function BuscaRegistros() {

    var mydata=document.getElementById("lugar").value;
    var mydata2=document.getElementById("fecha").value;

        var db = openDatabase('sightings03', '1.0', 'Test DB', 2 * 1024 * 1024);

    db.transaction(function (tx) {      
      tx.executeSql('SELECT  CommonName FROM Sights03 WHERE location=**"mydata"** AND datte="**mydata2**"' , [], function (tx, results) {
   var len = results.rows.length, i;
   for (i = 0; i < len; i++){

     document.despliega.desp.options[i]=new Option(results.rows.item(i).CommonName,i);

   }
 }, null);

});
}
4

1 回答 1

0

你在问如何连接字符串?你和+操作员一起做。

一般来说是这样的:

var mydata = "hello";
var string = "the value is: " + mydata;
console.log(string); // the value is: hello

所以你可能会这样做:

tx.executeSql('SELECT  CommonName FROM Sights03 WHERE location="' + mydata + '" AND datte="' + mydata2 + "' , [], function (tx, results) {
于 2013-09-16T02:34:00.773 回答