GWT统计div中的行数 [英] GWT count the number of rows in a div

查看:106
本文介绍了GWT统计div中的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

中的行数


我在页面布局中有一个div,用户将在其中输入文本:

 < div>用户文字将会放在这里< / div> 

我想要计算div在布局中实际占用的文本行数输入文字。注意这将根据屏幕分辨率或窗口大小而有所不同。



有没有办法做到这一点?



更妙的是,有没有办法让div高度以像素为单位?



我使用GWT,但JavaScript解决方案也可以。

谢谢!

解决方案


更好的是,有没有办法以像素为单位获取div高度?


如果您有 com.google .gwt.user.client.Element ,然后调用

  element.getClientHeight()

从getClientHeight()的Javadoc中:


以像素为单位返回元素的内部高度,包括填充,但不包括
水平滚动条的高度,边框或边距。

如果您有一个Widget,例如 com.google.gwt.user.client.ui.Label ,使用

  label.getElement()。getClientHeight()

在某些情况下,在 Scheduler.scheduleDeferred 中调用它,以确保在执行高度计算之前所有样式都已应用。


Possible Duplicate:
How to get number of rows in <textarea >?

I have a div inside a page layout, and the user will enter text in it:

 <div> user text will go here </div>

I would like to count the number of text rows the div actually occupies in the layout once the user has entered text. Notice this will vary according to the screen resolution, or the window size.

Is there a way to do so?

Even better, is there a way to get the div height in pixels?

I'm using GWT, but a JavaScript solution would do as well.

Thanks!

解决方案

Even better, is there a way to get the div height in pixels?

If you have a com.google.gwt.user.client.Element, then just call

element.getClientHeight()

From the Javadoc of getClientHeight():

Returns the inner height of an element in pixels, including padding but not the horizontal scrollbar height, border, or margin.

If you have a Widget, e.g. a com.google.gwt.user.client.ui.Label, use

label.getElement().getClientHeight()

In some circumstances, it may be useful to call this within Scheduler.scheduleDeferred, to make sure all styling has been applied before the height calculation is performed.

这篇关于GWT统计div中的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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