问题描述
我在网格中有一个文本字段,我想在其中关闭文本换行,但如果需要换行,则显示带有全文的工具提示。那么,我怎么能检测一个字段是否需要换行?
I have a textfield in a grid in which I wish to turn off text wrapping, but display a tooltip with the full text if wrapping is required. So, how could I detect if a field needs to wrap?
我试图查询该字段的长度,但它是在 em
或 px
,具体取决于用户是否调整了大小。我怎样才能获得包装状态?
I tried to query the field's length, but it was either in em
or in px
based on if the user resized it. How could I get the wrapping status?
推荐答案
检测文本是否包装的选项 - 创建(例如,使用jQuery)一个具有相同字体设置的不可见范围和 white-space:nowrap
,将其设置为 text
到该字段的内容并检查如果跨度的宽度大于字段的宽度(以像素为单位,通过 width()
获得)
An option to detect if the text wraps - create (with jQuery, for instance) an invisible span with the same font settings and white-space: nowrap
, set it's text
to the field's content and check if the span's width is bigger than the field's width (in pixels, obtained via width()
)
工作小提琴:
这篇关于如何检测文本字段是否需要包装在JavaScript / dojo中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!