当前位置: 首页 > 图文教程 > 网络编程 > Javascript > tbody元素支持嵌套的注意方法

Javascript
JavaScript中的Navigator浏览器对象
JavaScript中的Screen屏幕对象
JavaScript中的Window窗口对象
JavaScript中的History历史对象
JavaScript中的Location地址对象
JavaScript中的Document文档对象
JavaScript中的事件处理
JavaScript中的对象化编程
JavaScript框架编程
JavaScript的Cookies
JavaScript表单常用验证集合
javascript 实现的多浏览器支持的贪吃蛇webgame
表现、结构、行为分离的选项卡效果
用JavaScript 判断用户使用的是 IE6 还是 IE7
msn上的tab功能Firefox对childNodes处理的一个BUG
jquery 插件 人性化的消息显示
零基础学JavaScript最新动画教程+iso光盘下载
用jQuery实现检测浏览器及版本的脚本代码
在Javascript类中使用setTimeout
Javascript 写的简单进度条控件

Javascript 中的 tbody元素支持嵌套的注意方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 323 ::
收藏到网摘: n/a

function addMessage(messageID,userName,userCreateDate,articleCount,subject,body,creationDate,modifiedDate)
{
var br;
var row = document.createElement("tr");
var cell = document.createElement("td");
var cellTr = document.createElement("tr");
var cellTd = document.createElement("td");
cellTd.appendChild(document.createTextNode("用户名:"+userName));
cellTr.appendChild(cellTd);
cell.appendChild(cellTr);
cellTd = document.createElement("td");
cellTd.appendChild(document.createTextNode("创建时间:+userCreateDate"));
cellTr.appendChild(cellTd);
cell.appendChild(cellTr);
cellTd = document.createElement("td");
cellTd.appendChild(document.createTextNode("发表文章:"+articleCount));
cellTr.appendChild(cellTd);
cell.appendChild(cellTr);
row.appendChild(cell);
cell = document.createElement("td");
cellTr = document.createElement("tr");
cellTd = document.createElement("td");
cellTd.appendChild(document.createTextNode("发表时间:"+creationDate+" "+"修改时间:"+modifiedDate));
cellTr.appendChild(cellTd);
cell.appendChild(cellTr);
cellTr = document.createElement("tr");
cellTd = document.createElement("td");
cellTd.appendChild(document.createTextNode(subject));
br = document.createElement("br");
cellTd.appendChild(br);
cellTd.appendChild(document.createTextNode(body));
cellTr.appendChild(cellTd);
cell.appendChild(cellTr);
row.appendChild(cell);
document.getElementById("messageList").appendChild(row);
}
以上代码在ie中出现"意外的调用了方法或属性访问",错误指向最后一句.望各大侠指点迷津
评价:
你这段代码感觉不优雅~没有重用性~性能底~、
建议:
1>采用函数封装实现重用。
2>对于table的内部嵌套采用如下格式:

<table>
<tbody>
<tr>
<td></td>
...
</tr>
...
</tbody>
<tbody>
</tbody>
...
</table>

对table动态生成,采用从内到外添加的方案。另尽可能少使用document.createTextNode,性能低。
3>如果你的table不是在页面加载时需要执行,建议在<script中添加defer即
<script defer>
</script>

4>另外尽量采取对传值对象的封装,调用一次即可。即,可以将你的表格数据封装成[]或{}(当然内部有模型实现)的策略。
5>如果你js好的话,可以采用prototype做得更完美!
以上意见仅供参考。