在 Firefox 14.0.1 中使用 jQuery 获取 CSS 边框值 [英] Getting CSS border value with jQuery in Firefox 14.0.1
问题描述
我在 Firebug 控制台中运行以下代码.
I run the following code in the Firebug console.
$('img').css('border', 'solid 2px red').css('border');
出现红色图片边框,但返回空字符串,这是为什么?
The red image borders appear, but it returns an empty string, why is this?
它在 Chrome 和 Safari 开发者工具中运行良好.
It works fine in Chrome and Safari developer tools.
更新:jQuery 文档说获取 CSS 值时不支持速记属性.但是,我也尝试了以下操作,但在 Firefox 中没有成功(在 Chrome 和 Safari 中都可以使用)
Update: The jQuery docs say that shorthand properties are not supported when getting CSS values. However I have also tried the following with no luck in Firefox (All work in Chrome and Safari)
$('img').css('border-style', 'solid').css('border-style');
$('img').css('borderStyle', 'solid').css('borderStyle');
$('img').css('border', 'solid 2px green').css('borderStyle');
推荐答案
引用 .css
文档.
不支持简写 CSS 属性(例如边距、背景、边框).例如,如果要检索渲染的边距,请使用:$(elem).css('marginTop')
和 $(elem).css('marginRight')
,等等.
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-width
、border-style
和 border-color
相关属性.
For the case of border
, you need to use the border-width
, border-style
and border-color
related properties.
例如border-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');
这篇关于在 Firefox 14.0.1 中使用 jQuery 获取 CSS 边框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!