2011-09-08 68 views
1

.addClass在Firefox中不適用於我,它只適用於從CSS或class="hovering中取出<tr>標籤中的background:#f2f2f2;。 否則這部作品在所有的瀏覽器,瀏覽器,IE和Operajquery衝突tr:懸停和.addclass在Firefox中

<style> 

     .addToFav div{background:url('/images/star_no.png') no-repeat scroll !important; height:25px; margin:0 auto; width:25px; z-index: 999} 

     .addedToFav div{background:url('/images/star_yes.png') no-repeat scroll !important; height:25px; margin:0 auto; width:25px; cursor:default;} 

     tr.hovering:hover{ background-color:#f2f2f2} 

</style> 


<script> 
    $(document).ready(function() 
     { 

     $("a.addToFav").click(function(){ 


      $($(this).removeClass("addToFav").addClass("addedToFav")); 

     }); 

    }); 
</script> 


      <table><tr class="hovering"><td> 
       <div style="float:right"><a class="addToFav" href="#"> 
       <div></div> 
       </a> 
       </div> 
      </td></tr></table> 

可能這是一個錯誤嗎?

+0

您不需要在'$(...)'中包裝第二行。可能不是你的解決方案,但仍然不是你應該做的。 – Dennis

回答

0

不知道爲什麼你的不工作,但我改變了懸停爲jQuery調用,並刪除了CSS懸停的風格。

非常奇怪的問題。 +1喜歡它!

<script> 
    $(document).ready(function() { 

     $("a.addToFav").click(function() { 
      $(this).removeClass("addToFav"); 
      $(this).addClass("addedToFav"); 
     }); 

     $("tr.hovering").hover(function() { $(this).addClass("trhover"); }, function() { $(this).removeClass("trhover"); }); 
    }); 
</script> 


<table><tr class="hovering"><td> 
    <div style="float:right"> 
     <a class="addToFav" href="#"><div></div></a> 
    </div> 
</td></tr></table> 

<style> 
    .trhover{ background-color:#f2f2f2 } 
    .addToFav div{background:url(http://www.localisado.com/images/star_no.png) no-repeat scroll; height:25px; margin:0 auto; width:25px; z-index: 999} 
    .addedToFav div{background:url(http://www.localisado.com/images/star_yes.png) no-repeat scroll; height:25px; margin:0 auto; width:25px; cursor:default;} 
</style> 
+0

將懸停更改爲一個稱爲工作的Jquery!是的,這是一個奇怪的問題,這是我第48小時試圖找到答案,謝謝! –

1

addedToFav類如果您設置background-color然後將!important添加到它。如果頁面上存在其他衝突的樣式規則,這將確保提供更高的優先級。