可能重複:
Is it possible to append to innerHTML without destroying descendants' onclick functions?如何在不刪除之前的innerHTML的情況下使用innerHTML?
我想一個數組轉換成HTML表格,但innerHTML的刪除它以前寫的。下面是代碼:
<html><div id="tablaP"></div>
function cargar2() {
document.getElementById('tablaP').innerHTML= "<table>"
var h=1
for (i=0;i<miArray.length;i++){
document.getElementById('tablaP').innerHTML = '<tr>'
for (j=0;j<miArray[i].length;j++){
document.getElementById("tablaP").innerHTML = '<td><td>'
}
document.getElementById('tablaP').innerHTML = '</tr>'
h++
}
document.getElementById('tablaP').innerHTML = '</table>'
}
這裏還有一個關於這個專題的SO問題:http://stackoverflow.com/questions/595808/is-it-possible-to-append-to-innerhtml-without-destroying-descendants-onclick-fu – 2012-04-03 11:24:02