如何在 jquery 中将 div 元素的可见属性设置为 true 或 false?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3834207/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do i set a visible property of a div element to true or false in jquery?
提问by bill
I would like to be able to do this:
我希望能够做到这一点:
$(".panel").visible = true;
but this doesnt work
但这不起作用
回答by Nick Craver
For the display
CSS property, use .show()
, .hide()
or .toggle()
to affect whether it displays, like this:
对于display
CSS 属性,使用.show()
,.hide()
或.toggle()
来影响它是否显示,如下所示:
$(".panel").show();
//or to hide:
$(".panel").hide();
//toggle show/hide
$(".panel").toggle();
//or show/hide based on boolean:
$(".panel").toggle(bool);
For the visibility
CSS property, you need to set it manually (jQuery is mostly built around display
), using .css()
like this:
对于visibility
CSS 属性,您需要手动设置它(jQuery 主要围绕 构建display
),使用.css()
如下:
$(".panel").css("visibility", "visible");
//or:
$(".panel").css({ visibility: "visible"});
回答by Marcel Verwey
For me this worked:
对我来说这有效:
document.getElementById('my_elementid').style.visibility='visible';
回答by maxspan
you can by using ClientScript on serverside call your jquery method
您可以通过在服务器端使用 ClientScript 调用您的 jquery 方法
ClientScript.RegisterStartupScript(this.GetType(), "hideslidertab", "hideslidertab();", true);