博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
about selection and range
阅读量:7119 次
发布时间:2019-06-28

本文共 1455 字,大约阅读时间需要 4 分钟。

The fundamental difference is that a Selection represents the user's selection, while Rangerepresents a continuous part of a document independently of any visual representation. ASelection can (almost) be expressed in terms of zero, one or more Ranges but Ranges can also be created and modified completely independently of the selection.

There is some overlap in functionality: for example, Selection's deleteFromDocument() is equivalent to calling deleteContents() on all of its component Ranges, and you can get the boundaries of the most recently selected Range in the selection using the anchorNode,anchorOffsetfocusNode and focusOffset properties. However, there are some crucial differences:

  • Selection may contain multiple Ranges. However, the only major browser to support this currently is Firefox.
  • Selection may be "backwards", by which I mean that the end boundary of the selection (represented by focusNode and focusOffset) may occur earlier in the document than the start boundary (anchorNode and anchorOffset). A Range has no direction.
  • toString() works differently. In most browsers (although notably not IE 9), calling toString() on a Selection object returns only the visible text that is selected, while calling toString() on a Range will return a concatenation of all text nodes within the range, including those within <script>elements and elements hidden via CSS.

转载于:https://www.cnblogs.com/argb/archive/2011/12/07/2279391.html

你可能感兴趣的文章
Python OpenCV学习笔记之:使用MOG2视频背景消除
查看>>
8月第三周网络安全:境内感染网络病毒主机数73.7万个
查看>>
【Android】Service生命周期回顾
查看>>
11月国内浏览器市场份额:IE、Chrome均遭蚕食
查看>>
Windows下pip安装包报错:Microsoft Visual C++ 9.0 is required Unable to find vcvarsall.bat
查看>>
【公开课视频】ASP.NET MVC+EF入门-20130315
查看>>
Thinkphp 公共函数自动加载
查看>>
Linux内核之数据双链表
查看>>
【云计算的1024种玩法】巧用迁云工具轻松实现服务器迁移到ECS
查看>>
MaxCompute,基于Serverless的高可用大数据服务
查看>>
Linux下MySQL表名区分大小写
查看>>
mysql主从配置
查看>>
《算法图解》之散列表
查看>>
golang for switch break 使用
查看>>
PHP自己实现var_dump函数
查看>>
A simple poem
查看>>
故事板控件无法和代码关联的问题解决
查看>>
锁分段技术、ConcurrentHashMap、扩容
查看>>
恭喜51CTO视频课程认证讲师、博主李海园喜得姐妹花
查看>>
我的友情链接
查看>>