2011-09-08 36 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添加到它。如果页面上存在其他冲突的样式规则,这将确保提供更高的优先级。