Jamebo

导航

使用JavaScript创建Table时,用cellSpacing而不是cellspacing

今天遇到一个问题,我试图使用javascript创建一个Table,希望生成的HTML如下

<table cellpadding="0px" cellspacing="0px" >
 ...
</table>
我使用了如下代码:

var _tableRoot = document.createElement("table");
_tableRoot.setAttribute("cellspacing", "0");
_tableRoot.setAttribute("cellpadding", "0");

IE和FireFox生成的HTML都是如上所示,按理说就应该出现我想要的效果。但是实际上,在IE中cellspacing和cellpadding都不起作用。

最后终于找到一个解决方案(Google后发现已经有同样的案例):

使用 cellSpacing 而不是 cellspacing

使用 cellPadding 而不是 cellpadding

即:

_tableRoot.setAttribute("cellSpacing", "0");
_tableRoot.setAttribute("cellPadding", "0");

posted on 2008-02-05 17:41  一直在学习...  阅读(1652)  评论(1编辑  收藏  举报