javascript 在我的情况下如何隐藏和显示 div 边框线?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7471952/
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 to hide and show div border line in my case?
提问by Leem
I have a div element:
我有一个 div 元素:
<div id="fruit-part">
<input type="radio" name="fruits" value="apple">Apple
<input type="radio" name="fruits" value="orange">Orange
</div>
My css to define the div border color
我的css定义div边框颜色
#fruit-part {
border: 1px solid #cc3;
}
By using jQuery: $('#fruit-part').hide()
and $('#fruit-part').show()
I can easily hideand showthe content inside the div
, BUT not the div border line.
通过使用jQuery:$('#fruit-part').hide()
而且$('#fruit-part').show()
我可以很容易隐藏和显示里面的内容div
,而不是在div边界线。
As you saw above, my div
has a border line with color "#cc3", I am wondering, how to use jQuery to also hide and show the div border line?
正如您在上面看到的,我div
有一条颜色为“#cc3”的边框线,我想知道如何使用 jQuery 来隐藏和显示 div 边框线?
回答by cheeken
Move your CSS properties to a class, and then add/remove that class from fruit-part
.
将您的 CSS 属性移动到一个类,然后从fruit-part
.
.bordered {
border: 1px solid #cc3;
}
#fruit-part {}
$('#fruit-part').addClass('bordered');
$('#fruit-part').removeClass('bordered');
回答by Rob W
Use the css
method of JQuery:
使用css
JQuery的方法:
$("#fruit-part").css("border", "");
回答by Artem Koshelev
/* CSS */
.noborder { border: 0; }
//Hide border
$('#fruit-part').addClass('noborder');
//Show border
$('#fruit-part').removeClass('noborder');
回答by Jon Adams
$('#fruit-part').css('border', '');
and $('#fruit-part').css('border', '1px solid #cc3');
$('#fruit-part').css('border', '');
和 $('#fruit-part').css('border', '1px solid #cc3');
回答by marissajmc
You can just use $('#fruit-part').toggle();
to show and hide the whole div.
您可以仅用于$('#fruit-part').toggle();
显示和隐藏整个 div。
Demo - http://jsfiddle.net/hNxQ5/