`

动态添加表格行时的style的设置

阅读更多
以前看到别人的帖子说在动态设置cell风格时遇到问题,最近
自己也遇到同样的问题,就是在向table中insertCell()时,
无法给它的style属性设置一些类似于boder-bottom之类的风格。

在网上也查了很多种解决办法,比如下面的几种方式:

var   newRow   =   [TableObject].insertRow(i);
var   newCell   =   newRow.insertCell();

1.   newCell.style[ "boder-bottom "]   =   "1px   solid   silver ";

2.   newCell.setAttribute( "style ",   "1px   solid   silver ");

3.   newCell.style.boder-Bottom   =   "1px   solid   silver ";

这几种方法经过测试,都不能用,最后一种甚至是语法错误。

后来发现,对于这种中间带“-”的style属性,如果用
newCell.style.boderBottom   =   "1px   solid   silver ";
这样的方法,就可以解决不能设置的问题,也就是单纯地把
小横线“-”去掉就可以了。

用同样的方法,就可以给 "font-size ",   "background-color ",  
"text-align "等等类似的属性动态赋值了。

另外,对于一个newCell要设置许多属性的话,可以用
with   (newCell.style)   {
fontSize   =   "9pt ";
borderBottom   =   "1px   solid   silver ";
}
这样的方法来设置,减少代码字数。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics