---
title: "点评无刷新评论(tBodies[0])"
author: "digilover"
date: "2012-05-04T09:06:00Z"
tags: []
categories: ["Web前端"]
slug: "tbodies-0"
draft: false
lastmod: "2012-05-04T09:06:00Z"
id: 1504100
url: "https://digilover.iteye.com/blog/1504100"
---

点评无刷新评论

&lt;script type="text/javascript"&gt;

     function addComment(){

  var name = document.getElementById("name").value;

  var comment = document.getElementById("comment").value;

  var tableComment = document.getElementById("tableComment");

  var tr = document.createElement("tr");

  var td1 = document.createElement("td");

  td1.innerText = name;

  tr.appendChild(td1);

  

  var td2 = document.createElement("td");

  td2.innerText =comment ;

  tr.appendChild(td2);

  tableComment.tBodies\[0].appendChild(tr);//tBodies\[0]表示第一个表单。

  }

&lt;/script&gt;

&lt;table id="tableComment"&gt;

     &lt;tbody&gt;

      &lt;tr&gt;&lt;td&gt;猫猫&lt;/td&gt; &lt;td&gt;沙发耶 &lt;/td&gt; &lt;/tr&gt;

     &lt;/tbody&gt;

 &lt;/table&gt;

    昵称：&lt;input id="name" type="text"&gt;&lt;br&gt;

    &lt;textarea  id="comment" rows="2" cols="6"&gt;&lt;/textarea&gt;&lt;br&gt;

         &lt;input type="button" value="评论" onclick="addComment()"&gt;  

&lt;!--EndFragment--&gt;