<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<table width="1600" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF"
bordercolorlight="#666666" bordercolordark="#FFFFFF" id="comment">
<tr>
<td width="18%" height="27" align="center" bgcolor="#E5BB93">评论人</td>
<td width="82%" align="center" bgcolor="#E5BB93">评论内容</td>
</tr>
</table><br>
<form name="form1" method="post" action="">
评论人:<input name="person" type="text" id="person" size="40">
评论内容:<textarea name="content" cols="60" rows="3" id="content"></textarea><br><br>
<input type="button" value="发表" onclick="addElement()">
<input type="reset" value="清空">
<input type="button" value="删除第一条评论" onclick="deleteFristE()">
<input type="button" value="删除最后一条评论" onclick="deleteLastE()">
</form>
<script>
function addElement(){
var person = document.createTextNode(form1.person.value);
var content= document.createTextNode(form1.content.value);
var td_person = document.createElement("td");
var td_content= document.createElement("td");
var tr = document.createElement("tr");
var tbody = document.createElement("tbody");
td_person.appendChild(person);
td_content.appendChild(content);
tr.appendChild(td_person);
tr.appendChild(td_content);
tbody.appendChild(tr);
var table = document.getElementById("comment");
table.appendChild(tbody);
form1.person.value = "";
form1.content.value = "";
}
function deleteFristE(){
var table = document.getElementById("comment");
if(table.rows.length>1){
table.deleteRow(1);
}
}
function deleteLastE(){
var table = document.getElementById("comment");
if(table.rows.length>1){
table.deleteRow(table.rows.length-1);
}
}
</script>
</body>
</html>