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

所属分类: 网络编程 / JavaScript 阅读数: 593
收藏 0 赞 0 分享
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做得更完美!  
以上意见仅供参考。
更多精彩内容其他人还在看

深入解析Vue 组件命名那些事

本篇文章主要介绍了深入解析Vue 组件命名那些事,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Vue学习笔记进阶篇之vue-cli安装及介绍

这篇文章主要介绍了Vue学习笔记进阶篇之vue-cli安装及介绍,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

jquery版轮播图效果和extend扩展

这篇文章主要为大家详细介绍了jquery版轮播图效果,以及extend扩展的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

jQuery Validate格式验证功能实例代码(包括重名验证)

本文通过实例代码给大家介绍了jQuery Validate格式验证功能,代码中包括重名验证的方法,需要的的朋友参考下吧
收藏 0 赞 0 分享

Angular.js中angular-ui-router的简单实践

本篇文章主要介绍了Angular.js中angular-ui-router的简单实践,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

JavaScript实现二维坐标点排序效果

这篇文章主要为大家详细介绍了JavaScript实现二维坐标点排序效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

深入理解vue2.0路由如何配置问题

本篇文章主要介绍了vue2.0路由配置问题,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

基于bootstrap实现多个下拉框同时搜索功能

这篇文章主要为大家详细介绍了基于bootstrap实现多个下拉框同时搜索功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

JavaScript 值类型和引用类型的初次研究(推荐)

这篇文章主要介绍了JavaScript 值类型和引用类型的初次研究,需要的朋友可以参考下
收藏 0 赞 0 分享

利用jQuery异步上传文件的插件用法详解

这篇文章主要介绍了利用jQuery异步上传文件的插件用法详解,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多