繁体   English   中英

如何在没有“ .css('lineHeight');”和“ .css(font-size);”的情况下使用Jquery获取文本中行的大小?

[英]How to get the size of a row in a text with Jquery without “.css('lineHeight');” and “.css(font-size);”?

嗨,我在使用JavaScript的Samsung Smart TV SDK进行开发时遇到了问题(大部分代码都在使用JQuery)。 我需要在div中获得一行的大小,但在Samsung TV 2011中,

$('#element').css('font-size')

$('#element').css('line-height')

不起作用(这是关于2011的软件问题,因为2012和2013可以正常工作)。 没有人知道如何在没有这两种方法的情况下在Jquery或javascript中获取行的大小吗?

提前致谢。

尝试用outerHeight()

var height = $('#element').outerHeight();

或者,也许您正在寻找innerHeight():

var height = $('#element').innerHeight();

如果您实际上想返回行高,请使用此...

function getStyle(el,styleProp)
{
    var x = document.getElementById(el);
    if (x.currentStyle)
        var y = x.currentStyle[styleProp];
    else if (window.getComputedStyle)
        var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
    return y;
}

然后像...使用它

getStyle('#test', 'line-height' )

从这里开始... JavaScript:查找DIV的行高,而不是CSS属性,而是实际的行高

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM