获取font css属性在使用jQuery的IE和Firefox中不起作用 [英] Getting font css property does not work in IE and Firefox with jQuery

查看:92
本文介绍了获取font css属性在使用jQuery的IE和Firefox中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用以下代码获取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 rendered border-width, use: $( elem ).css( "borderTopWidth" ), $( elem ).css( "borderBottomWidth" ), and so on.

这篇关于获取font css属性在使用jQuery的IE和Firefox中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆