【问题标题】:Getting font css property does not work in IE and Firefox with jQuery使用 jQuery 在 IE 和 Firefox 中获取字体 css 属性不起作用
【发布时间】:2014-12-17 18:34:49
【问题描述】:

当我尝试使用 IE 或 Firefox 使用以下代码获取元素的整个字体样式时,我只得到一个空结果,但使用 Chrome 和 Opera 时,我得到了 "normal normal bold normal 20px/normal arial",正如我所预料的那样。

<!-- HTML -->
<div id="test" style="font: bold 20px arial; color: red;">test</div>

// JS
alert($('#test').css('font'));

为什么会发生这种情况,否则我如何获得完整的字体属性?

小提琴: http://jsfiddle.net/mwj12xkv/

【问题讨论】:

标签: javascript jquery html css


【解决方案1】:

您必须查询您感兴趣的各个font-* 属性。来自the css documentation

虽然可以在某些浏览器中使用,但不能保证检索速记 CSS 属性(例如,marginbackgroundborder)。例如,如果要检索呈现的border-width,请使用:$( elem ).css( "borderTopWidth" )$( elem ).css( "borderBottomWidth" ) 等。

【讨论】:

    猜你喜欢
    • 2016-05-28
    • 2017-10-13
    • 1970-01-01
    • 2015-08-16
    • 1970-01-01
    • 1970-01-01
    • 2014-12-23
    • 1970-01-01
    • 2016-09-21
    相关资源
    最近更新 更多