CSS 使用 jquery 更改标签标签的可见性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17864617/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 23:40:24  来源:igfitidea点击:

change visibility of label tag using jquery

cssjquery-ui

提问by priya

I have a label with hidden visibility on page load. How can i make it visible using jquery

我有一个在页面加载时隐藏可见性的标签。如何使用 jquery 使其可见

<label for="error" style="margin:100px auto 60px auto;color:Red; line-height:40px;font-size:medium;visibility:hidden">error occured</label>

I am able to hide it.

我能够隐藏它。

  $('label[for="error"]').hide();

This doesn't work

这不起作用

 $('label[for="error"]').show(); 

回答by vsr

Set the CSS property visibilityto visible.

将 CSS 属性可见性设置为visible.

$('label[for="error"]').css('visibility', 'visible');

回答by Charlie74

Change your code as follows:

更改您的代码如下:

<label for="error" style="margin:100px auto 60px auto;color:Red; line-height:40px;font-size:medium;display:none">error occured</label>

I've replaced your visibility:hiddenwith display:none.

我已经visibility:hiddendisplay:none.

You can then use the jQuery hide()and show()functions.

然后,您可以使用 jQuery hide()show()函数。

回答by Dhaval Marthak

Visibility:hiddenand display:noneboth are the different things:

Visibility:hiddendisplay:none两者的不同的事情:

You can check it's difference Play

你可以检查它的不同播放

You are hiding your element with

你正在隐藏你的元素

visibility:hidden

visibility:hidden

try display:noneinstead visibility: hidden

尝试display:none代替visibility: hidden

回答by twinlakes

Your css has "visibility:hidden", which is responsible for hiding the labels, not the jquery method. Use "display:none" instead

你的 css 有“visibility:hidden”,它负责隐藏标签,而不是 jquery 方法。改用“显示:无”

回答by TheAnchorsmith

Try to use display:none instead of visibility:hidden I've made a jsFiddle for you.

尝试使用 display:none 而不是visibility:hidden 我为你制作了一个jsFiddle。

label[for="error"]{
    margin:100px auto 60px auto;
    color:Red; 
    line-height:40px;
    font-size:medium;
    display:none;    
}

http://jsfiddle.net/Pghy3/

http://jsfiddle.net/Pghy3/