<head>
<title>评论</title>
<script type="text/javascript" >
function AddComment() {
var nickname = document.getElementById("nickname").value;
var comment = document.getElementById("comment").value;
var tableComment = document.getElementById("tableComment");
var tr = document.getElementById("tr");
var tdnickname = document.createElement("td");
tdnickname.innerText = nickname;
tr.appendChild(tdnickname);
var tdcoment = document.createElement("td");
tdcoment.innerText = comment;
tr.appendChild(tdcoment)
tableComment.tBodies[0].appendChild(tr);
}
</script>
</head>
<body>
莫哈皮莫哈皮莫哈皮
莫哈皮
莫哈皮
莫哈皮莫哈皮莫哈皮莫哈皮莫哈皮莫哈皮莫哈皮莫哈皮莫哈皮莫哈皮
<p>评论区</p>
<table id="tableComment">
<tr><td>毛毛:</td><td>沙发耶!</td></tr>
</table>
昵称:<input type="text" id="nickname" /><br />
<textarea rows="10" id="comment"></textarea>
<input type="button" value="提交" onclick="AddComment()"/>
</body>
------解决方案--------------------------------------------------------
var tr = document.getElementById("tr");
======>
你的<tr>没id
------解决方案--------------------------------------------------------
var tr = document.getElementById("tr");
执行后tr的值是NULL