我有一张桌子,我想从每个单元格中显示一个弹出窗口。但是我无法让我的代码工作。弹出窗口的代码使整个表格消失。
以下是创建表的功能:
function(json) {
var koosteRivi = ["Kaikki asiakkaat"];
var html="<table id ='lasku'>";
html+="<thead>";
html+="<tr>";
for(var i=0;i<json.vuosi[0].length;i++) {
var cell=json.vuosi[0][i];
html+="<th class=\"yla otsikko\">";
html+=cell;
html+="</th>";
koosteRivi.push(0);
}
html+="<th class=\"yla otsikko\">";
html+="Koko tilikausi";
html+="</th>";
html+="</tr>";
html+="</thead>";
for(var row=1;row<json.vuosi.length;row++) {
var yht = 0;
if(row%2 == 0) {
html+="<tr>";
} else {
html+="<tr id =\"jokatoinen\">";
}
html+="<td>";
html+=json.vuosi[row][0];
html+="</td>";
for(var i=1;i<json.vuosi[row].length;i++) {
var asiakasKkCell=json.vuosi[row][i];
koosteRivi[i]+=asiakasKkCell;
html+="<td>";
html+=formatSum(parseFloat(asiakasKkCell),","," ",CURRENCY);
html+="</td>";
yht+=parseFloat(asiakasKkCell);
}
html+="<th class=\"otsikko\">";
html+=formatSum(yht,","," ",CURRENCY);
html+="</th>";
html+="</tr>";
}
html+="<tr>";
html+="<th class=\"ala otsikko\">";
html+=koosteRivi[0];
html+="</th>";
var lastCell=0;
for(var i=1;i<koosteRivi.length-1;i++) {
var cell=koosteRivi[i];
html+="<th class=\"ala otsikko\">";
html+=formatSum(parseFloat(cell),","," ",CURRENCY);
html+="</th>";
lastCell+=cell;
}
html+="<th class=\"ala otsikko\">";
html+=formatSum(parseFloat(lastCell),","," ",CURRENCY);
html+="</th>";
html+="</tr>";
html+="</table>";
document.getElementById("as-invoicing-cumulYear").innerHTML=html;
}
这是我用来创建链接的代码:
function addRowHandlers() {
var table = document.getElementById("lasku");
var rows = table.getElementsByTagName("tr");
for (i = 0; i < rows.length; i++) {
var currentRow = table.rows[i];
currentRow.onclick = createClickHandler(currentRow);
}
}
function createClickHandler(row){
return function() {
var cell = row.getElementsByTagName("td")[0];
var id = cell.innerHTML;
alert("id:" + id);
};
}
addRowHandlers();
我做错了什么?