[code="html"]
div设置了text-overflow属性,它的内容像素大于div的宽度,选中div中的文字,怎么获得文字的像素?
不同的browser的默认字体大小(px)可能不一样。
另外,选中的字体,可能有多种不同的"style".
所以,基本是没有办法确认的。
但是,可以确认选中的文本。
function getSelText()
{
var txt = '';
if (window.getSelection)
{
txt = window.getSelection();
}
else if (document.getSelection)
{
txt = document.getSelection();
}
else if (document.selection)
{
txt = document.selection.createRange().text;
}
return txt;
}
获得Graphics 应用Graphics.MesureString方法,应用它当前的字段,获取长度
打开qq,ctrl+alt+a,量一下