我有三个不同ID的div。我想将myModal + i
连接到data-target
属性,但我不确定如何做到这一点。这是我的代码:
success: function (response) {
var work;
var res = response.split("§");
var modalid;
for (var i = 0; i < res.length - 1; i++) {
modalid = "myModal" + i;
work = res[i].split("^");
document.getElementById('eventi').innerHTML += "Cena del: " + work[0] + "<button type=\"button\" data-toggle=\"modal\" data-target=\"#\"\">leggi di piu</button>" + "<br>";
document.getElementById('description' + (i)).innerHTML = work[1];
}
}
答案 0 :(得分:0)
我已将包装引号更改为单引号,以防止需要转义内部引号。
document.getElementById('eventi').innerHTML +=
'Cena del: ' + work[0] + '<button type="button" data-toggle="modal" data-target="#' + modalid + '">leggi di piu</button><br>';