无论如何以编程方式隐藏 jQuery UI 按钮?
我想用 jQuery UI Button 做这样的事情:
$button.button();
// ...
$button.button('hide');
// ...
$button.button('show');
类似于 enable /disable
有效。手动隐藏和显示按钮 ($button.hide();
$button.show();
) 会导致 jQuery UI CSS 出现一些非常奇怪的格式。 ?
我在这里缺少一些简单的东西吗
I'd like to do something like this, with jQuery UI Button:
$button.button();
// ...
$button.button('hide');
// ...
$button.button('show');
Similar to how enable/disable
works. Hiding and showing the button manually ($button.hide();
$button.show();
) is resulting in some really screwy formatting with the jQuery UI CSS...
Am I missing something simple here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
只需执行标准的
$button.hide()
就可以很好地完成工作,它到底搞砸了什么?您可以执行
$button.css('display', 'none')
但这就是$button.hide()
所做的一切。我很确定没有办法做到你所要求的,即使有它也只能设置显示:没有像我刚才提到的方法。您可能会更好地弄清楚为什么设置 display none 会搞乱页面其他地方的 CSS。
Just doing the standard
$button.hide()
should do the job fine, what exactly is it screwing up?You could do
$button.css('display', 'none')
but this is all that$button.hide()
does anyway.I'm pretty sure there isn't a way to do what you ask, and even if there would it only set display: none like the methods I just mentioned. You might be better of figuring out why setting display none is screwing up your CSS elsewhere on the page.
如果您使用
visibility
样式而不是display
按钮应该能够正确创建。visibility:hidden
样式只是使元素不可见; $.hide() 使用的display: none
样式实际上从渲染的 DOM 中删除该元素。简而言之:
我之前已经做过几次了。
If you use the style
visibility
instead ofdisplay
the button should be able to create properly. Thevisibility: hidden
style just makes the element invisible; thedisplay: none
style which $.hide() uses actually removes the element from the rendered DOM.So in short try:
I've had to do this a few time before.
我知道这个是旧的,但是...不是最初在 CSS 中定义隐藏的按钮,而是使用 ui-helper-hidden 类定义它。这样它将被隐藏,直到您实例化它。 display:none 隐藏一个元素,并且不会占用任何空间。该元素将被隐藏,页面将显示为好像该元素不存在一样。这与隐藏按钮不同,因为这样它仍然会占用屏幕空间。
如果您需要它在实例化后最初保持隐藏状态,您可以将其隐藏。
生成的 jQuery UI 按钮将具有 display:inline-block,覆盖 ui-helper-hidden 的 display:none。
我从来没有遇到过它呈现奇怪的问题,所以你的问题可能有一个潜在的问题。
Old one this, I know, but... Instead of defining the button to be hidden in the CSS initially, define it with a class of ui-helper-hidden. That way it will be hidden until you instantiate it. display:none hides an element, and it will not take up any space. The element will be hidden, and the page will be displayed as if the element is not there. This is different to making the button hidden, as that way it should still take up screen space.
If you need it to initially stay hidden after instantiation you can hide it
The resulting jQuery UI button will have display:inline-block, overriding the ui-helper-hidden's display:none.
I've never had a problem with it rendering strangely, so your problem may have had an underlying issue.
这对我来说是解决方法。如果 jquery ui 改变了实现,那么就没有保证了。
$('#button-el').next().hide();
This is workaround solution for me. What if jquery ui changes implementation then there is no guarantee.
$('#button-el').next().hide();
对我有用的是:
onclick="$(this).parent().css('display', 'none');"
What worked for me was this:
onclick="$(this).parent().css('display', 'none');"