表格插入行的一点小问题

xutower 2007-01-06 03:17:58
最近喜欢在Firefox下做东西,方便调试脚本。今天做插入行
var newRow=document.getElementById("mytable").insertRow(insertRowIndex);

这样应该算建立一行了吧。然后我直接用newRow.innerHTML=getCol();

getCol() 返回的是"<td>aa</td><td>bb</td>"
等这样的东西,这个在firefox下通过,成功插入了行。

但是在IE下报错 : 未知的运行时错误。

ie下可能是在insertRow后就要立马insertCell建立<td>才可以,但是因为我有很多地方要用到插入行,而数据都是可以从 getCol()方法取得的,如果每次都要insertCell的话,要写很多代码,这不划算。
所以请问我如何才能建立行,并从getCol()直接拿到<td> ?
...全文
320 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
daseng123 2007-01-08
  • 打赏
  • 举报
回复
ooReport开发平台演示报告
主站地址:http://www.ooreport.com/
http://soft.etcell.com/topicView.aspx?Id=89159(论坛地址)

(平台总体介绍 flash文件14.5M)
http://www.ooreport.com/flash/ooReport01.swf

(制作采集程序并且提交到数据库方法演示 flash文件5.5M)
http://www.ooreport.com/flash/ooReport02.swf

一个对ooReport网上直报/数据分系统的Flash讲解,看一下,提提建议

WinTable报表设计器下载地址:http://www.etcell.com/download.asp?id=51
ooReport开发工具下载地址:http://www.etcell.com/download.asp?id=5101

测试环境 需要的话,通知我,给你开通账号
http://www.ooreport.com/ooReports/
http://www.ooreport.com/ooReports/indexlg.aspx?sid=TEST
然后选择
10、ooReport网上直报数据分析平台


haothing 2007-01-07
  • 打赏
  • 举报
回复
可以这样
document.getElementById("mytable").parentElement.innerHTML = "<table><tr>" + getCol() + "</tr></table>";

To change the contents of the table, tFoot, tHead, and tr elements, use the table object model described in How to Build Tables Dynamically. For example, use the rowIndex property or the rows collection to retrieve a reference to a specific table row. You can add or delete rows using the insertRow and deleteRow methods. To retrieve a reference to a specific cell, use the cellIndex property or the cells collection. You can add or delete rows using the insertCell and deleteCell methods. To change the content of a particular cell, use the innerHTML property.

jeremychin 2007-01-07
  • 打赏
  • 举报
回复
顶楼上的 字符串赋值比生成节点效率更高
My97 2007-01-06
  • 打赏
  • 举报
回复
可以用dom做
var d = document.createElement('table');
返回i行j列可以这样用
d.cells[i].rows[j]
xutower 2007-01-06
  • 打赏
  • 举报
回复
查到原来tr在ie不能做 innerHTML的,Faint~~~ ,不知道还有没办法

87,910

社区成员

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

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