使用 jquery 更改边框底部颜色?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1509316/
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
Change border-bottom color using jquery?
提问by halocursed
I want to change the color of the bottom border using jquery..Thanks
我想使用 jquery 更改底部边框的颜色..谢谢
回答by nil
$("selector").css("border-bottom-color", "#fff");
- construct your jQuery object which provides callable methods first. In this case, say you got an
#mydiv
, then$("#mydiv")
- call the
.css()
method provided by jQuery to modify specified object's css property values.
- 首先构造提供可调用方法的 jQuery 对象。在这种情况下,假设你有一个
#mydiv
,那么$("#mydiv")
- 调用
.css()
jQuery提供的方法修改指定对象的css属性值。
回答by John Boker
$('#elementid').css('border-bottom', 'solid 1px red');
回答by nil
to modify more css property values, you may use css object. such as:
要修改更多 css 属性值,您可以使用 css 对象。如:
hilight_css = {"border-bottom-color":"red",
"background-color":"#000"};
$(".msg").css(hilight_css);
but if the modification code is bloated. you should consider the approachMarch suggested. do it this way:
但是如果修改代码臃肿。你应该考虑三月建议的方法。这样做:
first, in your css file:
首先,在你的 css 文件中:
.hilight { border-bottom-color:red; background-color:#000; }
.msg { /* something to make it notifiable */ }
second, in your js code:
其次,在你的js代码中:
$(".msg").addClass("hilight");
// to bring message block to normal
$(".hilight").removeClass("hilight");
if ie 6 is not an issue, you can chain these classes to have more specific selectors.
如果 ie 6 不是问题,您可以链接这些类以获得更具体的选择器。
回答by Mark Schultheiss
If you have this in your CSS file:
如果你的 CSS 文件中有这个:
.myApp
{
border-bottom-color:#FF0000;
}
and a div for instance of:
和一个div,例如:
<div id="myDiv">test text</div>
you can use:
您可以使用:
$("#myDiv").addClass('myApp');// to add the style
$("#myDiv").removeClass('myApp');// to remove the style
or you can just use
或者你可以使用
$("#myDiv").css( 'border-bottom-color','#FF0000');
I prefer the first example, keeping all the CSS related items in the CSS files.
我更喜欢第一个示例,将所有与 CSS 相关的项目保存在 CSS 文件中。