js 显示的元素在一段时间内无法访问

发布于 2025-01-01 14:33:27 字数 658 浏览 1 评论 0原文

我在表中有几个按钮(每行一个按钮)并使用 jQuery 显示/隐藏它们:

$('#some-id tr').hover(
    function() { $(this).find('.button-class').removeAttr('disabled').css(...); },
    function() { $(this).find('.button-class').attr('disabled', true).css(...); }
);

它可以正确地显示/隐藏。 问题是有时会显示无法从浏览器访问按钮(对左键和右键单击没有反应,浏览器不显示工具提示)。可以通过右键单击浏览器窗口的其余部分来激活(并非总是如此)。

在 Firefox 和 Chrome 中测试。

解决了?非常有趣。上面代码中的 .css(...) 包含设置 background: none/url(image.png)。按钮没有文本,因此在使用 disabled="disabled"background: none; 时不可见。我简单地尝试了 .show()/.hide() 并且无法重现该问题。很好,但是第一版除了冗余之外还有什么问题呢?

I have several buttons in the table (one button for each row) and show/hide them using jQuery:

$('#some-id tr').hover(
    function() { $(this).find('.button-class').removeAttr('disabled').css(...); },
    function() { $(this).find('.button-class').attr('disabled', true).css(...); }
);

It properly works for showing/hiding.
The catch is sometimes shown buttons aren't accessible from the browser (don't react to left and right clicks, browsers don't show tooltip). Could be liven up by right click on the rest of browser window (not always).

Tested in Firefox and Chrome.

SOLVED? Very interesting. .css(...) in the code above are contained setting background: none/url(image.png). Buttons have no text, so were invisible with disabled="disabled" and background: none;. I tried simply .show()/.hide() and can't reproduce the problem. Great, but what was wrong with the first edition except of its redundancy?

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

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

发布评论

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

评论(1

蒗幽 2025-01-08 14:33:27

确保将代码包装在 jQuery 的 .ready() 函数或其他类似函数中,例如 $(window).load()

这是使用 .ready() 时的样子:

$(function() {
     $('#some-id tr').hover(
         function() { $(this).find('.button-class').removeAttr('disabled').css(...); },
         function() { $(this).find('.button-class').attr('disabled', true).css(...); }
     );
});

Make sure you wrap your code in jQuery's .ready() function, or some other such function, such as $(window).load().

Here's how it would look with .ready():

$(function() {
     $('#some-id tr').hover(
         function() { $(this).find('.button-class').removeAttr('disabled').css(...); },
         function() { $(this).find('.button-class').attr('disabled', true).css(...); }
     );
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文