---
title: "给 Table 增加行的 JavaScript 函数"
author: "vbtboy"
date: "2011-02-21T17:51:54Z"
tags: []
categories: ["Web前端"]
slug: "table-javascript"
draft: false
lastmod: "2011-02-21T17:51:54Z"
id: 913447
url: "https://vbtboy.iteye.com/blog/913447"
---

function addRowToTable(strTableId, arrTdText)
{
var objTable = document.getElementById(strTableId);
if(objTable == null) {
return;
}

var objTableBody = objTable.getElementsByTagName("TBODY");
var row = document.createElement("TR")
for(var i = 0; i < arrTdText.length; i++) {
var col = document.createElement("TD")
col.appendChild(document.createTextNode(arrTdText*))
row.appendChild(col);
}

objTableBody.appendChild(row);
}