0

我正在尝试编写一个查询,该查询从表中提取和转换数据,然后插入到另一个表中。如果我添加字符串,它会起作用,但是当我添加变量时它不会。它给了我空桌子!

function dodb() {

    var name = document.getElementsByName('prezime');
    var elements = document.getElementsByName('bt');

    for (var i = 0; i <= elements.length; i++) {
        var oelements = elements[i];
        oelements.onclick = (function(){
        var name1 = name[i].firstChild.nodeValue;
        return function() {
            db.transaction(function (tx) {
                var a = "INSERT INTO racersA SELECT * FROM racers WHERE prezime=%name1%";
                tx.executeSql(a);
            });
        }
        })(i);
    }
}
4

2 回答 2

0

您没有将任何变量放入 SQL 中,因此由于它是简单的 Javascript,因此您需要将变量与字符串连接起来

应该

var a = "INSERT INTO racersA SELECT * FROM racers WHERE prezime='" + name1 + "'";
于 2012-09-23T11:19:08.477 回答
0

或者,使用参数化 SQL

var a = "INSERT OR REPLACE INTO racersA SELECT * FROM racers WHERE prezime = ?";
tx.executeSql(a, [name]);
于 2012-09-25T03:33:04.617 回答