这是我的问题:
当我说 getelementbyid("table1") 它说“未捕获的类型错误:无法设置属性 'innerHTML' of null ”
我正在通过 java 脚本渲染一个动态表,如下所示:
function mainProcessing()
{
<% ProductController pc=new ProductController();%>
var val = <%=pc.doTask()%>
var jobj=JSON.stringify(val);
document.write(jobj);
alert(jobj);
var obj=JSON.parse(jobj);
alert("jobj");
alert(obj.toString());
var object = eval("(" + jobj+ ")");
alert("this part is done");
return object;
}
function drawtable()
{
var JSONObj=mainProcessing();
var tablecontents = "";
for (var i = 0; i < 5; i ++)
{
tablecontents += "<tr>";
tablecontents += "<td>" + i + "</td>";
tablecontents += "<td>" + i * 100 + "</td>";
tablecontents += "<td>" + i * 1000 + "</td>";
tablecontents += "</tr>";
}
document.write(JSONObj.toString());
alert("just outside nested loop");
document.getElementById("table1").innerHTML = tablecontents;
}
为了测试,我在表中插入了随机值。
那个html部分是这样的:
<title>Indian Divine !!!</title>
</head>
<body onload="drawtable()">
<center>
<h1>my name is jobj</h1>
<table id="table1">
</table>
</center>
</body>
</html>
浏览器用户是 Chrome。IDE 使 Juno 黯然失色