使用 jQuery 更改边框底部颜色?

发布于 2024-08-06 08:39:27 字数 29 浏览 2 评论 0原文

如何使用 jQuery 更改底部边框的颜色?

How to change the color of the bottom border using jQuery?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

回心转意 2024-08-13 08:39:27
$("selector").css("border-bottom-color", "#fff");
  1. 构造你的 jQuery 对象,它首先提供可调用的方法。在本例中,假设您有一个 #mydiv,然后 $("#mydiv")
  2. 调用 jQuery 提供的 .css() 方法修改指定对象的 css 属性值。
$("selector").css("border-bottom-color", "#fff");
  1. construct your jQuery object which provides callable methods first. In this case, say you got an #mydiv, then $("#mydiv")
  2. call the .css() method provided by jQuery to modify specified object's css property values.
王权女流氓 2024-08-13 08:39:27
$('#elementid').css('border-bottom', 'solid 1px red');
$('#elementid').css('border-bottom', 'solid 1px red');
情感失落者 2024-08-13 08:39:27

要修改更多CSS属性值,您可以使用CSS对象。比如:

hilight_css = {"border-bottom-color":"red", 
               "background-color":"#000"};
$(".msg").css(hilight_css);

但是如果修改代码比较臃肿。您应该考虑 方法 March 建议的。这样做:

首先,在你的 css 文件中:

.hilight { border-bottom-color:red; background-color:#000; }
.msg { /* something to make it notifiable */ }

其次,在你的 js 代码中:

$(".msg").addClass("hilight");
// to bring message block to normal
$(".hilight").removeClass("hilight");

如果 ie 6 不是问题,你可以链接这些类以获得更具体的选择器。

to modify more css property values, you may use css object. such as:

hilight_css = {"border-bottom-color":"red", 
               "background-color":"#000"};
$(".msg").css(hilight_css);

but if the modification code is bloated. you should consider the approach March suggested. do it this way:

first, in your css file:

.hilight { border-bottom-color:red; background-color:#000; }
.msg { /* something to make it notifiable */ }

second, in your js code:

$(".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.

忘年祭陌 2024-08-13 08:39:27

如果你的 CSS 文件中有这个:

.myApp
{
    border-bottom-color:#FF0000;
}

和一个 div 例如:

<div id="myDiv">test text</div>

你可以使用:

$("#myDiv").addClass('myApp');// to add the style

$("#myDiv").removeClass('myApp');// to remove the style

或者你可以只使用

$("#myDiv").css( 'border-bottom-color','#FF0000');

我更喜欢第一个例子,将所有与 CSS 相关的项目保留在 CSS 文件中。

If you have this in your CSS file:

.myApp
{
    border-bottom-color:#FF0000;
}

and a div for instance of:

<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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文