<html>
<head>
<title></title>
</head>
<body>
<script>
var daten = [{x: 1, y: 2}, {x: 3, y: 4}, {x: 5, y: 6}];
function cb(ret) {
alert("gewählt wurde: " + ret[0] + " - " + ret[1] + " - " + ret[2]);
}
function bsp(daten, cb) {
var out = [];
var tab = "<table>";
for (var i = 0; i < daten.length; ++i) {
tab += "<tr>";
tab += "<td><button type='button'>" + daten[i].x + "</button></td>";
tab += "<td><button type='button'>" + daten[i].y + "</button></td>";
tab += "</tr>";
}
tab += "</table>";
document.body.innerHTML = tab;
var table = document.body.firstChild;
function getClickHandler(i) {
return function() {
out[i] = this.innerHTML;
table.deleteRow(this.parentNode.parentNode.rowIndex);
if (!table.rows.length) {
document.body.innerHTML = "";
cb(out);
}
};
}
for (var i = 0; i < daten.length; ++i) {
table.rows[i].cells[0].firstChild.onclick = table.rows[i].cells[1].firstChild.onclick = getClickHandler(i);
}
}
bsp(daten, cb);
</script>
</body>
</html>
Aber vorsicht, das ist schnell zusammengeschustert und soll nur das Prinzip verdeutlichen.