简体   繁体   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);”?

Hi I'm having problems developing with Samsung Smart TV SDK, which use javascript (I'm using JQuery for most part of code). 嗨,我在使用JavaScript的Samsung Smart TV SDK进行开发时遇到了问题(大部分代码都在使用JQuery)。 I need to get the size of a row in a div but in Samsung TV 2011 the 我需要在div中获得一行的大小,但在Samsung TV 2011中,

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

and

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

doesn't work (it's a software problem about 2011 because in 2012 and 2013 work correctly). 不起作用(这是关于2011的软件问题,因为2012和2013可以正常工作)。 Anyone know how to get the size of a row in Jquery or javascript without this two methods? 没有人知道如何在没有这两种方法的情况下在Jquery或javascript中获取行的大小吗?

Thanks in advance. 提前致谢。

Try with outerHeight() : 尝试用outerHeight()

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

Or maybe you are looking for innerHeight(): 或者,也许您正在寻找innerHeight():

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

If you actually want to return the line height use this... 如果您实际上想返回行高,请使用此...

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;
}

Then use it like... 然后像...使用它

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

From here... JavaScript: Find DIV's line-height, not CSS property but actual line-height 从这里开始... JavaScript:查找DIV的行高,而不是CSS属性,而是实际的行高

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

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