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

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 265 ::
收藏到网摘: 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做得更完美!
以上意见仅供参考。