【问题标题】:Jquery conflict tr:hover and .addclass in firefoxFirefox 中的 Jquery 冲突 tr:hover 和 .addclass
【发布时间】:2011-11-12 15:24:29
【问题描述】:

.addClass 在 Firefox 中对我不起作用,只有当我从 CSS 样式块中删除 background:#f2f2f2; 或从 <tr> 标记中删除 class="hovering” 时它才有效。 否则,这适用于所有浏览器、Chrome、IE 和 Opera。

<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>

这可能是一个错误吗?

【问题讨论】:

  • 您不需要将第二行包含在 $(...) 中。可能不是您的解决方案,但仍然不是您应该做的事情。

标签: jquery firefox html-table tablerow


【解决方案1】:

addedToFav 类中,如果您要设置background-color,则将!important 添加到其中。这将确保在页面上存在其他冲突的样式规则时给予更多优先权。

【讨论】:

    【解决方案2】:

    不知道为什么你的不起作用,但我将悬停更改为 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>
    

    【讨论】:

    • 将悬停更改为名为 work 的 Jquery!是的,这是一个奇怪的问题,这是我试图找到答案的第 48 小时,谢谢!
    猜你喜欢
    • 1970-01-01
    • 2015-02-05
    • 1970-01-01
    • 2016-08-14
    • 2021-03-06
    • 2015-04-07
    • 2014-09-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多