获取font css属性在使用jQuery的IE和Firefox中不起作用 [英] Getting font css property does not work in IE and Firefox with jQuery
问题描述
当我尝试使用以下代码获取IE或Firefox的元素的整个字体样式时,我只得到一个空结果,但是使用Chrome和Opera我得到正常正常粗体正常20px /正常的arial
正如我所料。
When I try to get the whole font style of an element with IE or Firefox with the following code I only get a empty result, but with Chrome and Opera I get "normal normal bold normal 20px/normal arial"
as I would have expected.
<!-- HTML -->
<div id="test" style="font: bold 20px arial; color: red;">test</div>
// JS
alert($('#test').css('font'));
Wyh会发生这种情况,如何获得完整的字体属性呢?
Wyh does this happen and how do I get the complete font property otherwise?
FIDDLE:
http://jsfiddle.net/mwj12xkv/
推荐答案
您需要查询您感兴趣的单个字体 - *
属性in。来自 css
文档:
You'll have to query the individual font-*
properties you're interested in. From the css
documentation:
检索速记CSS属性(例如,
margin
,background
,border
)虽然可以在某些浏览器中使用,但不能保证。例如,如果要检索呈现的border-width
,请使用:$(elem).css(borderTopWidth)
,$(elem).css(borderBottomWidth)
,依此类推。
Retrieval of shorthand CSS properties (e.g.,
margin
,background
,border
), although functional with some browsers, is not guaranteed. For example, if you want to retrieve the renderedborder-width
, use:$( elem ).css( "borderTopWidth" )
,$( elem ).css( "borderBottomWidth" )
, and so on.
这篇关于获取font css属性在使用jQuery的IE和Firefox中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!