Internet Explorer文本范围中的字符偏移量 [英] Character offset in an Internet Explorer TextRange

查看:146
本文介绍了Internet Explorer文本范围中的字符偏移量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,没有简单的方法从Internet Explorer中的TextRange对象中检索字符偏移量。 W3C Range对象具有一个节点以及该节点内文本的偏移量。 IE似乎只是有像素偏移。有一些方法可以创建,扩展和比较范围,因此可以编写一个算法来计算字符偏移量,但我觉得我必须错过某些东西。



那么,计算Internet Explorer TextRange开始的字符偏移量最简单的方法是什么?

我会建议< a href =http://code.google.com/p/ierange/ =nofollow noreferrer> IERange ,或者仅仅是 TextRange - 至$ DOM Range 算法。



2011年8月9日更新



我现在建议使用我自己的 Rangy 库,它类似从理念到IERange,但更充分的实现和支持。


As far as I can tell there's no simple way of retrieving a character offset from a TextRange object in Internet Explorer. The W3C Range object has a node, and the offset into the text within that node. IE seems to just have pixel offsets. There are methods to create, extend and compare ranges, so it would be possible to write an algorithm to calculate the character offset, but I feel I must be missing something.

So, what's the easiest way to calculate the character offset of the start of an Internet Explorer TextRange?

解决方案

I'd suggest IERange, or just the TextRange-to-DOM Range algorithm from it.

Update, 9 August 2011

I'd now suggest using my own Rangy library, which is similar in idea to IERange but much more fully realized and supported.

这篇关于Internet Explorer文本范围中的字符偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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