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

时间:2013-09-16 02:15:33

标签: javascript

如何将值从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);

});
}

1 个答案:

答案 0 :(得分: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) {