
<html>
<head>
<script type="text/javascript">
function show()
{
var tab = documentgetElementById("test") ;
//表格行数
var rows = tabrowslength ;
//表格列数
var cells = tabrowsitem(0)cellslength ;
alert("行数"+rows+"列数"+cells);
}
</script>
</head>
<body>
<table id="test" border="1">
<tr>
<td> </td><td>nbsp;</td>
</tr>
<tr>
<td> </td><td>nbsp;</td>
</tr>
</table>
<input type="button" onclick="show();"/>
</body>
</html>
<!DOCTYPE HTML>
<html>
<head>
<meta charset=UTF-8>
<title>table</title>
<style>
table {
margin:auto;
width: 60%;
border: 1px solid black;
border-collapse: collapse;
}
table caption {
color: blue;
font: 34px consolas bold;
}
table th, table td {
border: 1px solid black;
text-align:center;
}
table th {
font: 20px consolas bold;
background-color: gray;
}
table tr:nth-child(n+2){
background-color: cyan;
}
table tr:nth-child(2n+2) {
background-color: red;
}
</style>
<script>
var data = [
{id: "001", fullname: "张三", sex: "男", score: [98,33,48]},
{id: "002", fullname: "李四", sex: "w", score: [11,22,33]},
{id: "003", fullname: "kyo", sex: "m", score: [22,33,55]},
{id: "004", fullname: "yamazaki", sex: "w", score: [99, 100, 80]}
];
var Student = function (id, fullname, sex, score)
{
thisid = id;
thisfullname = fullname;
thissex = sex;
thisscore = score;
}
var Score = function (chinese, math, english)
{
thischinese = chinese;
thismath = math;
thisenglish = english;
}
var students = [];
for (var i = 0; i < datalength; i++)
{
var d = data[i];
var s = d["score"];
studentspush(new Student (d["id"], d["fullname"], d["sex"], new Score(s[0], s[1], s[2])));
}
onload = function ()
{
var table = documentcreateElement("table");
var tbody = documentcreateElement("tbody");
tableappendChild(tbody);
var caption = tablecreateCaption();
captioninnerHTML = "学生成绩表";
var tr = tbodyinsertRow (0);
var str = "学号,姓名,性别,语文,数学,<a href="https://wwwbaiducom/swd=%E8%8B%B1%E8%AF%AD&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Ydm1bdPAcdmWPbPjDsuyw90ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnH0YP1fzP1Rkn1ckrHTdrj6drf" target="_blank" class="baidu-highlight">英语</a>"split(",");
for (var i = 0; i < strlength; i++)
{
var th = documentcreateElement("th");
thinnerHTML = str[i];
trappendChild (th);
}
for (var i = 0; i < studentslength; i++)
{
var tr = tbodyinsertRow (tbodyrowslength);
var obj = students[i];
for (var p in obj)
{
var op = obj[p];
if (p != "score")
{
var td = trinsertCell (trcellslength);
tdinnerHTML = op;
}
else
{
for (var p in op)
{
var td = trinsertCell (trcellslength);
tdinnerHTML = op[p];
}
}
}
}
documentbodyappendChild(table);
}
</script>
<body>
</body>
</html>
以下为html+js实现表格添加一行的,附加代码注释,如果需要jquery的,
再联系,Q:672986035
<html>
<head>
<title>检测</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function AddRow(mytr) {
var tabAdd = documentgetElementById("tabAdd");
// 去掉注释的代码,则每次点击效果为先清除之前添加的行
// var lengthRow = tabAddrowslength;
// if (lengthRow > 1) {
// for (var j = 1; j < lengthRow; j++) {
// tabAdddeleteRow(j);
// }
// }
// 为表格 tabAdd 添加一行
var tabRow = tabAddinsertRow();
// 根据点击的行的列数,循环为tabRow添加每一列
var length = mytrcellslength;
for (var i = 0; i < length; i++) {
var tabCell = tabRowinsertCell();
tabCellinnerHTML = mytrcells[i]innerHTML;
}
}
</script>
</head>
<body>
<table id="tabOld" border="1" style="width:300px; text-align:center;">
<tr>
<th>序号</th>
<th>组织名</th>
</tr>
<tr onclick="AddRow(this)">
<td>1</td>
<td>组织一</td>
</tr>
<tr onclick="AddRow(this)">
<td>2</td>
<td>组织二</td>
</tr>
</table>
<br /><br />
<table id="tabAdd" border="1" style="width:300px; text-align:center;">
<tr>
<th>序号</th>
<th>组织名</th>
</tr>
</table>
</body>
</html>
你是有现成的数据源想要在spreadjs中添加表格来展示数据呢?
还是获取spreadjs中存在的表格中的数据?
如果是第一种:
你可以参考:
http://demogcpowertoolscomcn/SpreadJS/TutorialSample/#/samples/basicTable
如果是第二种:
跟获取单元格的数据一样可以是用sheetgetValue()来获取指定表格中单元格的数据。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)