這http://jsfiddle.net/UvYxc/工作
HTML
<table>
<tr style="background:red;" id= "2977" class ="x y z a b c" >
<td>RED</td>
</tr>
</table>
JS
document.getElementById("2977").style.backgroundColor="blue"
alert(document.getElementById("2977").style.backgroundColor);
或者
document.getElementById("2977").className += " blue";
document.getElementById("2977").className += " red";
function getStyle(el, cssprop){
//IE
if (el.currentStyle)
return el.currentStyle[cssprop]
//Firefox
else if (document.defaultView && document.defaultView.getComputedStyle)
return document.defaultView.getComputedStyle(el, "")[cssprop]
else //try and get inline style
return el.style[cssprop]
}
var el = document.getElementById("2977");
alert(getStyle(el, "backgroundColor"));
alert(getStyle(el, "color"));
here
你應該發佈更多的html。由於您發佈的js是有效的。桌子裏有tr嗎? – 2012-03-02 12:22:38