复制代码 代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script language="javascript" type="text/javascript">
function addRow() {
var newTR = document.getElementById("testTable").insertRow(document.getElementById("testTable").rows.length);
var newNameTD = newTR.insertCell(0);
newNameTD.innerHTML = "aa";
var newNameTD = newTR.insertCell(1);
newNameTD.innerHTML = "<input name='LastName' id='LastName' type='text' />";
var newNameTD = newTR.insertCell(2);
newNameTD.innerHTML = "<input name='BirthDay' id='BirthDay' type='text' />";
var newNameTD = newTR.insertCell(3);
newNameTD.innerHTML = "<input name='age' id='age' type='text' />";
}
function insertRow() {
var oTable = document.getElementById("table_info");
var oTr = oTable.insertRow();
var oTd = oTr.insertCell();
oTd.innerHTML = "新添加了一行";
}
function insertRow2() {
//获取table对象
var table = document.getElementById("table_info2");
//找到要添加button的td,这里以表格第一行第一列为例子
var oTd = table.rows[0].cells[0];
//添加button到td中,添加前吧td内容清空并赋予button的代码
oTd.innerHTML = "<button onclick='insertRow22()'>添加收费</button>";
}
function insertRow22() {
var oTable = document.getElementById("table_info2");
var oTr = oTable.insertRow();
var oTd = oTr.insertCell();
oTd.innerHTML = "新添加了一行";
}
function insertRow3() {
//获取table对象
var table = document.getElementById("table_info3");
//找到要添加button的td,这里以表格第一行第一列为例子
var oTd2 = table.rows[0].insertCell();
oTd2.innerHTML = "&nbps;";
}
function tableDiv() {
var maxRow = 4;
var maxCol = 8;
var strTbody = ["<table border='1'><tbody>"];
for (var i = 0; i < maxRow; i++) {
strTbody.push("<tr>");
for (var j = 0; j < maxCol; j++) {
strTbody.push("<td>test</td>");
}
strTbody.push("</tr>");
}
strTbody.push("</tbody></table>");
var obj = document.getElementById("tableDiv");
obj.innerHTML = strTbody.join("");
}
function init() {
var _table, _tbody, tr, td, text, maxRow, maxCol;
var docBody = document.body;
var _doc = document;
maxRow = 5;
maxCol = 8;
_table = _doc.createElement("table");
_table.border = "1";
_table.style.tableLayout = "fixed";
_tbody = _doc.createElement("tbody");
_table.insertBefore(_tbody, null);
docBody.insertBefore(_table, null);
for (var i = 0; i < maxRow; i++) {
tr = _doc.createElement("tr");
_tbody.insertBefore(tr, null);
for (var j = 0; j < maxCol; j++) {
td = _doc.createElement("td");
text = _doc.createTextNode("Text");
td.insertBefore(text, null);
tr.insertBefore(td, null);
}
}
}
</script>
</head>
<body>
<div>
<table id="testTable" border='1' cellspacing="1">
<tr>
<th>
FirstName
</th>
<th>
LastName
</th>
<th>
BirthDay
</th>
<th>
age
</th>
</tr>
<tr>
<td>
Jim
</td>
<td>
Green
</td>
<td>
L.A
</td>
<td>
23
</td>
</tr>
<tr>
<td>
Andrew
</td>
<td>
Hou
</td>
<td>
Xi'an
</td>
<td>
25
</td>
</tr>
</table>
<input type="button" id="aaa" value="+add new Row" onclick="addRow();" />
</div>
<br />
<hr />
<br />
<div>
<input type="button" value="按钮添加行" onclick="insertRow();" />
<table id="table_info" border="1">
<tr>
<th>
Name
</th>
<th>
Age
</th>
</tr>
</table>
</div>
<br />
<hr />
<br />
<div>
<input type="button" value="按钮中添加行" onclick="insertRow2();" />
<table id="table_info2" border="1">
<tr>
<th>
Name
</th>
<th>
Age
</th>
</tr>
</table>
</div>
<br />
<hr />
<br />
<div>
<input type="button" value="连续添加列" onclick="insertRow3();" />
<table id="table_info3" border="1">
<tr>
<th>
Name
</th>
<th>
Age
</th>
</tr>
</table>
</div>
<br />
<hr />
<br />
<div>
<input type="button" value="添加一个table" onclick="tableDiv();" />
<div id="tableDiv" />
</div>
<br />
<hr />
<br />
<div>
<input type="button" value="连续添加table" onclick="init();" />
</div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script language="javascript" type="text/javascript">
function addRow() {
var newTR = document.getElementById("testTable").insertRow(document.getElementById("testTable").rows.length);
var newNameTD = newTR.insertCell(0);
newNameTD.innerHTML = "aa";
var newNameTD = newTR.insertCell(1);
newNameTD.innerHTML = "<input name='LastName' id='LastName' type='text' />";
var newNameTD = newTR.insertCell(2);
newNameTD.innerHTML = "<input name='BirthDay' id='BirthDay' type='text' />";
var newNameTD = newTR.insertCell(3);
newNameTD.innerHTML = "<input name='age' id='age' type='text' />";
}
function insertRow() {
var oTable = document.getElementById("table_info");
var oTr = oTable.insertRow();
var oTd = oTr.insertCell();
oTd.innerHTML = "新添加了一行";
}
function insertRow2() {
//获取table对象
var table = document.getElementById("table_info2");
//找到要添加button的td,这里以表格第一行第一列为例子
var oTd = table.rows[0].cells[0];
//添加button到td中,添加前吧td内容清空并赋予button的代码
oTd.innerHTML = "<button onclick='insertRow22()'>添加收费</button>";
}
function insertRow22() {
var oTable = document.getElementById("table_info2");
var oTr = oTable.insertRow();
var oTd = oTr.insertCell();
oTd.innerHTML = "新添加了一行";
}
function insertRow3() {
//获取table对象
var table = document.getElementById("table_info3");
//找到要添加button的td,这里以表格第一行第一列为例子
var oTd2 = table.rows[0].insertCell();
oTd2.innerHTML = "&nbps;";
}
function tableDiv() {
var maxRow = 4;
var maxCol = 8;
var strTbody = ["<table border='1'><tbody>"];
for (var i = 0; i < maxRow; i++) {
strTbody.push("<tr>");
for (var j = 0; j < maxCol; j++) {
strTbody.push("<td>test</td>");
}
strTbody.push("</tr>");
}
strTbody.push("</tbody></table>");
var obj = document.getElementById("tableDiv");
obj.innerHTML = strTbody.join("");
}
function init() {
var _table, _tbody, tr, td, text, maxRow, maxCol;
var docBody = document.body;
var _doc = document;
maxRow = 5;
maxCol = 8;
_table = _doc.createElement("table");
_table.border = "1";
_table.style.tableLayout = "fixed";
_tbody = _doc.createElement("tbody");
_table.insertBefore(_tbody, null);
docBody.insertBefore(_table, null);
for (var i = 0; i < maxRow; i++) {
tr = _doc.createElement("tr");
_tbody.insertBefore(tr, null);
for (var j = 0; j < maxCol; j++) {
td = _doc.createElement("td");
text = _doc.createTextNode("Text");
td.insertBefore(text, null);
tr.insertBefore(td, null);
}
}
}
</script>
</head>
<body>
<div>
<table id="testTable" border='1' cellspacing="1">
<tr>
<th>
FirstName
</th>
<th>
LastName
</th>
<th>
BirthDay
</th>
<th>
age
</th>
</tr>
<tr>
<td>
Jim
</td>
<td>
Green
</td>
<td>
L.A
</td>
<td>
23
</td>
</tr>
<tr>
<td>
Andrew
</td>
<td>
Hou
</td>
<td>
Xi'an
</td>
<td>
25
</td>
</tr>
</table>
<input type="button" id="aaa" value="+add new Row" onclick="addRow();" />
</div>
<br />
<hr />
<br />
<div>
<input type="button" value="按钮添加行" onclick="insertRow();" />
<table id="table_info" border="1">
<tr>
<th>
Name
</th>
<th>
Age
</th>
</tr>
</table>
</div>
<br />
<hr />
<br />
<div>
<input type="button" value="按钮中添加行" onclick="insertRow2();" />
<table id="table_info2" border="1">
<tr>
<th>
Name
</th>
<th>
Age
</th>
</tr>
</table>
</div>
<br />
<hr />
<br />
<div>
<input type="button" value="连续添加列" onclick="insertRow3();" />
<table id="table_info3" border="1">
<tr>
<th>
Name
</th>
<th>
Age
</th>
</tr>
</table>
</div>
<br />
<hr />
<br />
<div>
<input type="button" value="添加一个table" onclick="tableDiv();" />
<div id="tableDiv" />
</div>
<br />
<hr />
<br />
<div>
<input type="button" value="连续添加table" onclick="init();" />
</div>
</body>
</html>
标签:
js,table
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“js添加table的行和列 具体实现方法”评论...
更新动态
2024年11月13日
2024年11月13日
- 刘欢《雨中的树(新歌加精选)2CD》德国HD24K金碟[WAV+CUE]
- 郑源 《世间情歌》6N纯银SQCD[WAV+CUE][1G]
- 群星《粤潮2HQII》头版限量编号[低速原抓WAV+CUE][991M]
- 群星《2023好听新歌21》十倍音质 U盘音乐[WAV分轨][1G]
- 《热血传奇》双11感恩回馈 超值狂欢30天
- 原神5.2版本活动汇总 5.2版本活动有哪些
- 张敬轩.2010-NO.ELEVEN【环球】【WAV+CUE】
- 黄丽玲.2006-失恋无罪【艾回】【WAV+CUE】
- 阿达娃.2024-Laluna【W8VES】【FLAC分轨】
- 宝可梦大集结段位等级划分表大全 大集结段位一览
- 龙腾世纪影障守护者工坊与装备如何升级 工坊与装备升级说明
- 龙腾世纪影障守护者全成就攻略分享 龙腾世纪4全成就列表一览
- 《剑星》更新四套全新战衣!
- 卡普空老将伊津野英昭宣布入职腾讯光子 开发3A动作
- 38岁梅根·福克斯官宣怀孕:将迎来第四个孩子