js 显示的元素在一段时间内无法访问
我在表中有几个按钮(每行一个按钮)并使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保将代码包装在 jQuery 的
.ready()
函数或其他类似函数中,例如$(window).load()
。这是使用
.ready()
时的样子: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()
: