日期:2014-05-17  浏览次数:20820 次

为什么innerHTML出现错误?
代码:
var   f   =   document.getElementById( "avote ");
f.innerHTML   =   f.innerHTML+ " <tr> <td> 123 </td> <td> 456 </td> <td> 789 </td> </tr> ";


错误提示:
行:   68

字符:   2

错误:   未知的运行时错误

代码:   0



------解决方案--------------------
innerHTML是写html语句,不能用在form中,按你的意思,是在表格中作修改
<table width= "100% " cellpadding=0 cellspacing=0 valign= "top ">
<form id= "avote " action= "addvoting.asp " method= "post " name= "addvote2 ">
<tr id= "add_tr ">
<td> 选项: </td>
<td> <a href= "# " onclick=add()> 添加 </a> </td>
</tr>
</form>
</table>
<script>
function add()
{

add_tr.innerHTML += " <tr> <td> 123 </td> <td> 456 </td> <td> 789 </td> </tr> ";
}
</script>

注意列数一致
------解决方案--------------------
innerHTML 对下面的对象只读:
COL,COLGROUP,FRAMESET,HTML,STYLE,TABLE,TBODY,TFOOT,THEAD,TITLE,TR.