2013-02-24 53 views
0

不工作我有一個HTML表:chaning CSS背景屬性在IE

<table id=mytable> 
<tr> 
<th>Configurations</th> 
<th>Dual 1.8GHz</th> 
<th>Dual 2GHz</th> 
<th>Dual 2.5GHz</th> 
</tr> 
</table> 

,然後我寫了下面:

<script type="text/javascript"> 

$('#mytable tr').hover(
    function() { 
    $(this).css("background","yellow"); 
    }, 
    function() { 
    $(this).css("background",""); 
    } 

); 

</script> 

當我將鼠標懸停在錶行,就成了黃色Firefox,但在IE中它變成了白色!有任何想法嗎?

+1

爲IE嘗試** backgroundColor **而不是**背景** – 2013-02-24 08:30:41

+0

我在IE9上測試了您的代碼,它是黃色:http://jsfiddle.net/uCKmj/242/ – richard 2013-02-24 08:34:06

+3

它會更乾淨,代替使用CSS更可靠。 'table tr:hover {background-color:yellow; }' – JJJ 2013-02-24 08:35:29

回答

1
<style> 
.someClass{/*all the proertiese you wanna set*/} 
</style> 
$('#mytable tr').hover(
    function() { 
    $(this).addClass('someClass'); 
    }, 
    function() { 
    $(this).removeClass('someClass') 
    } 

); 
0

更換

$(this).css("backgroundColor","yellow"); 

而且

$(this).css("backgroundColor",""); 

,或者你可以傳遞一個CSS屬性對象

$(this).css({ 
    background-color: 'yellow', 
    background-image: 'url("blablabla")' 
}); 
0

做:

$(this).css("backgroundColor","yellow"); 
//or 
$(this).css("background-color","yellow");