简体   繁体   English

隐藏元素而不在jquery中将显示设置为none

[英]hide element without setting the display to none in jquery

I want to fold a section of the form without setting its display to none . 我想折叠表单的一部分而不将其display设置为none If i set the display to none , the validation is bypassed that is why I don't want to set the display to none . 如果我将display设置为none ,则绕过验证,这就是为什么我不想将display设置为none I know I can set the visibility to hidden and visible but this solution is not feasible for rendering the view as the space for the folded section stays there. 我知道我可以将可见性设置为hiddenvisible但是此解决方案不可用于渲染视图,因为折叠部分的空间保留在那里。 This results in a very odd look of the view with an empty white space with no content on it. 这导致视图看起来非常奇怪,空白空间没有内容。

So my question is to hide a section of the html form (without intacting a placeholder for it) without setting its display to none , so that I could still perform the validation. 所以我的问题是隐藏html表单的一部分(没有为它插入占位符)而不将其display设置为none ,这样我仍然可以执行验证。

Some HTML code: 一些HTML代码:

<td style="margin: 5px; border-bottom: 1px solid; display:none; overflow: hidden;" colspan="3">
    <div>...</div>
</td>

The display is initially set to none but once it is unfolded for the first time, I am setting the height to 100% and removing the display style. display最初设置为无,但一旦首次展开,我将height设置为100%并删除display样式。

You can move it off the screen: 你可以把它从屏幕上移开:

$(elem).css("position", "absolute").css("left", -9999);

Or set it's height to 0: 或者将它的高度设置为0:

$(elem).css("height", 0);

虚假display:none的最简单方法display:none是通过将位置设置为绝对(因此元素从流中取出,不再影响外部元素的渲染)和隐藏的可见性(因此不再绘制)。

$(elem).css('visibility', 'hidden').css('position','absolute');

将元素的不透明度设置为0。

$(elem).css("opacity", 0);
$("#ele").css({"height" : 0, "width" : 0, "opacity" : 0});

Hiding an element with jquery... 用jquery隐藏元素......

$('element').addClass('hidden');

and in your CSS just use what ever you find appropriate to make that element "hidden" 并在您的CSS中使用您认为合适的内容使该元素“隐藏”

.hidden{
  /* whatever you find appropriate */
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM