gpt4 book ai didi

jquery - 在 Firefox 14.0.1 中使用 jQuery 获取 CSS 边框值

转载 作者:行者123 更新时间:2023-12-01 05:32:31 26 4
gpt4 key购买 nike

我在 Firebug 控制台中运行以下代码。

$('img').css('border', 'solid 2px red').css('border');

出现红色图像边框,但返回空字符串,这是为什么?

它在 Chrome 和 Safari 开发者工具中运行良好。

更新:jQuery 文档表示,获取 CSS 值时不支持简写属性。不过,我也在 Firefox 中尝试了以下操作,但没有成功(所有工作都在 Chrome 和 Safari 中进行)

$('img').css('border-style', 'solid').css('border-style');
$('img').css('borderStyle', 'solid').css('borderStyle');
$('img').css('border', 'solid 2px green').css('borderStyle');

最佳答案

引用.css文档。

Shorthand CSS properties (e.g. margin, background, border) are not supported. For example, if you want to retrieve the rendered margin, use: $(elem).css('marginTop') and $(elem).css('marginRight'), and so on.

对于 border 的情况,需要使用border-widthborder-styleborder-color相关属性。

例如边框颜色:

$('img').css('border-top-color', 'red').css('borderTopColor');
$('img').css('border-right-color', 'red').css('borderRightColor');
$('img').css('border-bottom-color', 'red').css('borderBottomColor');
$('img').css('border-left-color', 'red').css('borderLeftColor');

关于jquery - 在 Firefox 14.0.1 中使用 jQuery 获取 CSS 边框值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36408736/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com