切换“活动”状态使用 jQuery 类,再次单击按钮时样式保留,但在 Firefox 中删除了类

发布于 2024-10-09 22:20:10 字数 283 浏览 0 评论 0原文

我有一个问题。 - 仅在 Firefox 中

当我使用 jQuery 在链接上切换类“活动”时。如果我再次单击该链接,活动样式将保留。它仍然可见,直到我单击页面上的其他位置,但仅在 Firefox 中,但该类已被删除。

代码:

$('#quick-add-click').click( function() {
  $(this).find('a').toggleClass('active');
});

有人遇到类似的问题吗?有一个简单的修复方法吗?

I have a problem. - only in Firefox

When I use jQuery to toggle a class 'active' on a link. The active style remains if I click the link again. It remains visible until I click somewhere else on the page but only in Firefox yet the class has been removed.

CODE:

$('#quick-add-click').click( function() {
  $(this).find('a').toggleClass('active');
});

Anyone having any similar issues? Is there a simple fix?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

木槿暧夏七纪年 2024-10-16 22:20:10

您是否正在使用 Mootools,或者即使您没有使用 Mootools,Mootools 也会被加载(Joomla 系统会自动发生)。我在使用 Firefox/Mootools/VEMap(Bing 地图)时遇到问题,也许您也遇到类似的问题。

Are you using Mootools or is Mootools being loaded even if you're not using it (happens automatically with Joomla systems). I had a problem with Firefox/Mootools/VEMap (Bing Maps) maybe you're having a similar problem.

夏了南城 2024-10-16 22:20:10

无法重现它。

但是,也许您可​​以测试它是否可以在没有切换的情况下工作?

$('#quick-add-click').click( function() {
  if($(this).find('a').hasClass('active')) {
    $(this).find('a').removeClass('active');
  } else {
    $(this).find('a').addClass('active');
  }
});

Couldn't reproduce it.

However, perhaps you can test if it works without toggle?

$('#quick-add-click').click( function() {
  if($(this).find('a').hasClass('active')) {
    $(this).find('a').removeClass('active');
  } else {
    $(this).find('a').addClass('active');
  }
});
失去的东西太少 2024-10-16 22:20:10

最小的例子,在 OSX Firefox 上看不到这种行为,

<!DOCTYPE html>
<html>
    <head>
        <title>Test</title>
        <style>
            a.active { color: #f00; }
        </style>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
        <script>
            $(function() {
                $('#quick-add-click').click(function() {
                    $(this).find('a').toggleClass('active');
                });
            });
        </script>
    </head>
    <body>
        <div id="quick-add-click">
            <a href="#">Foobar</a>
        </div>
    </body>
</html>

你能用 Firebug 检查一下当活动类不再存在时该样式来自哪里吗?

Minimal example, cannot see that behaviour on OSX Firefox

<!DOCTYPE html>
<html>
    <head>
        <title>Test</title>
        <style>
            a.active { color: #f00; }
        </style>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
        <script>
            $(function() {
                $('#quick-add-click').click(function() {
                    $(this).find('a').toggleClass('active');
                });
            });
        </script>
    </head>
    <body>
        <div id="quick-add-click">
            <a href="#">Foobar</a>
        </div>
    </body>
</html>

Could you check with Firebug where that style comes from when active class is not present anymore?

楠木可依 2024-10-16 22:20:10

好的,我修复它的方法(以一种黑客的方式)是将 onfocus="blur()" 添加到锚元素

OK so the way I fixed it (in a hacky way) was to add onfocus="blur()" to the anchor element

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文