如何通过insertRow()插入行?

wunglee 2003-06-04 04:45:12
<html>
<head>
<script>
function appendTr(){
var to = document.all.item("testTable");
var insertedTr=to.insertRow();//为什么不会显示插入行?
insertedTr.bgColor="efefef";
//....如何添加cells以及其中的数据?
}
</script>
</head>
<body onload="appendTr()">
<table id="testTable">
</table>
</body>
</html>
...全文
194 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
方工 2003-06-05
  • 打赏
  • 举报
回复
// web color 216 sample
function MakeTable(){
var c = ["00","33","66","99","cc","ff"]
var i,j,k,s;
var tb = document.createElement("TABLE");
for(i=0;i<6;i++){
var tr = tb.insertRow();
for(j=0;j<6;j++){
for(k=0;k<6;k++){
var td = tr.insertCell();
s = "#" + c[i] + c[j] + c[k];
td.bgColor = s;
td.title = s;
}
}
}
document.body.appendChild(tb);
}
window.onload = MakeTable;
jsidiot 2003-06-05
  • 打赏
  • 举报
回复
<html>
<head>
<script>
function appendTr(){
var to = document.all.item("testTable");
var insertedTr=to.insertRow();//为什么不会显示插入行?
insertedTr.bgColor="efefef";
var insertTd=insertedTr.insertCell();
insertTd.innerText="I love you"
//....如何添加cells以及其中的数据?
}
</script>
</head>
<body onload="appendTr()">
<table id="testTable" border=1>
</table>
</body>
</html>
sportdog 2003-06-04
  • 打赏
  • 举报
回复
function add()
{ var madd=otable.rows.length;
var orow1=otable.insertRow(otable.rows.length);
//insert one row.
var arows=otable.rows;
//retrieve the rows collection for the table
var acells=orow1.cells;
//retrieve the cells collection for the new row
var ocell1_1=arows(orow1.rowIndex).insertCell(acells.length);
var ocell1_2=arows(orow1.rowIndex).insertCell(acells.length);
var ocell1_3=arows(orow1.rowIndex).insertCell(acells.length);
var ocell1_4=arows(orow1.rowIndex).insertCell(acells.length);
var ocell1_5=arows(orow1.rowIndex).insertCell(acells.length);
var ocell1_6=arows(orow1.rowIndex).insertCell(acells.length);
var ocell1_7=arows(orow1.rowIndex).insertCell(acells.length);
var ocell1_8=arows(orow1.rowIndex).insertCell(acells.length);
ocell1_1.innerHTML="<font size=2 color=red>删除</font>";
ocell1_2.innerHTML="<font style='cursor:hand;' size=2 color=green onclick=del()>"+madd+"</font>";
ocell1_8.innerHTML="<input type=hidden name=lsh"+madd+" size=10 value="+<%=e%>+madd+" >";
ocell1_4.innerHTML="<input type=text name=mc"+madd+" size=10>";
ocell1_5.innerHTML="<input type=text name=xh"+madd+" size=10>";
ocell1_6.innerHTML="<input type=text name=dw"+madd+" size=10>";
dog="document.frm1.jhj"+madd+".value";
ocell1_7.innerHTML="<input type=text name=jhj"+madd+" size=10 onchange='return checknum(eval(dog))'>";
flhtmladd="<select name=fl"+madd+"><option></option>"
<%if not rs1.BOF then rs1.MoveFirst
while not rs1.EOF%>
flhtmladd=flhtmladd+"<option value='<%=rs1("fl")%>'><%=rs1("fl")%></option>";
<%rs1.MoveNext
wend%>
flhtmladd=flhtmladd+"</select>";
ocell1_3.innerHTML=flhtmladd;
}
考点给你吧,msdn上可以查到
gzh_seagull 2003-06-04
  • 打赏
  • 举报
回复
<html>
<head>
<script>
function appendTr(){
var to = document.all.item("testTable");
var insertedTr=to.insertRow();//为什么不会显示插入行?
insertedTr.bgColor="efefef";
//....如何添加cells以及其中的数据?
var insertedTd=insertedTr.insertCell();
insertedTd.innerText="hi";
}
</script>
</head>
<body onload="appendTr()">
<table id="testTable">
</table>
</body>
</html>

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧