如何计算JavaScript中字符串的长度(以像素为单位)? [英] How to calculate the length (in pixels) of a string in JavaScript?

查看:96
本文介绍了如何计算JavaScript中字符串的长度(以像素为单位)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何计算JavaScript中字符串的长度(以像素为单位)?

How to calculate the length (in pixels) of a string in JavaScript?

推荐答案

鉴于有关您想要的新信息为文本溢出添加省略号,我认为文本溢出CSS属性是一种更好的方法。有关详细信息,请参阅quirksmode上的这篇文章: http://www.quirksmode.org/css/textoverflow。 HTML

Given the new information about your wanting to append an ellipsis for text overflow, I think the text-overflow CSS property is a better approach. See this article on quirksmode for more information: http://www.quirksmode.org/css/textoverflow.html

这篇关于如何计算JavaScript中字符串的长度(以像素为单位)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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