关于table等只读标签的innerHTML问题

function setTbodyHTML(id,tr){ 
	var dc = document.createElement('div'); 
	dc.innerHTML = ' <table> <tbody>'+tr+' </tbody> </table>'; 
	var oj = $(id); 
	while(oj.firstChild) oj.removeChild(oj.firstChild); 
	var tbody = dc.firstChild.firstChild; 
	while(tbody.firstChild) oj.appendChild(tbody.firstChild); 
} 

 

 

The property is read/write for all objects except the following, for which it is read-only: COL, COLGROUP, FRAMESET, HTML, STYLE, TABLE, TBODY, TFOOT, THEAD, TITLE, TR.
由于table,tbody等标签的属性是只读的,无法使用innerHTML。可以使用上面的方法折中处理!

你可能感兴趣的:(html)