如何使用jquery使可见的不可见控件可见?(隐藏并显示不起作用) [英] How can I make visible an invisible control with jquery? (hide and show not work)

查看:109
本文介绍了如何使用jquery使可见的不可见控件可见?(隐藏并显示不起作用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用jQuery更改控件的可见性?我有一个控件,它的可见属性为false(不是CSS).

How can I change the visibility of a control with jQuery? I have a control that its visible property to false (not css).

当我使用 show()函数没有任何反应时,看来 hide() show()方法适用于CSS控件集,不可见属性.

When I used show() function for it nothing happened, it seems that hide() and show() methods are for css set of a control, not visible property.

推荐答案

您无法使用jQuery,asp.net中的 visible ="false" 意味着控件 isn't呈现到页面中.如果您希望控件转到客户端,则需要执行 style ="display:none;" ,所以它实际上在HTML中,否则实际上没有任何内容可供客户端显示,因为该元素不在您的服务器发送的HTML中.

You can't do this with jQuery, visible="false" in asp.net means the control isn't rendered into the page. If you want the control to go to the client, you need to do style="display: none;" so it's actually in the HTML, otherwise there's literally nothing for the client to show, since the element wasn't in the HTML your server sent.

如果删除 visible 属性并添加 style 属性,则可以使用jQuery显示它,如下所示:

If you remove the visible attribute and add the style attribute you can then use jQuery to show it, like this:

$("#elementID").show();


旧答案(在帕特里克的渔获之前)

要更改 visibility ,您需要使用 .css() ,就像这样:


Old Answer (before patrick's catch)

To change visibility, you need to use .css(), like this:

$("#elem").css('visibility', 'visible');

除非您需要让元素占据页面空间,否则请在CSS中使用 display:none; 而不是 visibility:hidden; ,然后执行以下操作:

Unless you need to have the element occupy page space though, use display: none; instead of visibility: hidden; in your CSS, then just do:

$("#elem").show();

.show()

The .show() and .hide() functions deal with display instead of visibility, like most of the jQuery functions :)

这篇关于如何使用jquery使可见的不可见控件可见?(隐藏并显示不起作用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆