首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

javascript 操作table样式解决思路

2012-03-21 
javascript 操作table样式tableid toptablestyle width 100% height 74 trtd/td/tr/t

javascript 操作table样式
<table   id= "toptablestyle "   width= "100% "   height= "74 ">
            <tr>
                <td>
                </td>
            </tr>
</table>
其中样式定义为
#toptablestyle{
background:url(../Image/topimg.gif)   no-repeat   #E9EF82;
}
如何通过js来控制background样式
我写了以下这个javascript脚本为何不起作用
document.getElementById( 'toptablestyle ').style= 'background:url(../Image/testimg.gif)   no-repeat   #E9EF82 ';

[解决办法]
document.getElementById( 'toptablestyle ').style= 'background:url(../Image/testimg.gif) no-repeat #E9EF82 ';
=====>
document.getElementById( 'toptablestyle ').style.background= 'url(../Image/testimg.gif) no-repeat #E9EF82 ';
[解决办法]
document.getElementById( 'h3id ').style.padding-left= '10px ';
======>
document.getElementById( 'h3id ').style.paddingLeft= '10px ';
在设置style属性时,如style= "padding-left:10px "
在用style.?=?的方式设置时,如果属性里含有 "- ",一般都将 "- "去掉,而将 "- "后面的第一个字母大写,即style.paddingLeft= "10px "
再如:style= "background-color:#cccccc "
style.backgroundColor= "#cccccc "

热点排行