SlideShare une entreprise Scribd logo
1  sur  17
Télécharger pour lire hors ligne
Range 标准化
承玉@taobao
大纲
 获取 Range
 W3C Range
 IE Range
 IE -> W3C
读取
 标准:
 window 接口 的 getSelection 方法获得 Selection 对象,
Selection 对象的 getRangeAt 方法获得指定的 Range 对
象。
 window.getSelection().getRangeAt(index)
 IE:
 document.selection.createRange()
 从当前文本选择区域创建一个textrange
 或者在当前的控件选择下创建一个控件选择集合
W3C Range
 定义
 位置
 偏移量
 图解
 API
定义
 表示文档连续的一段内容范围,通过一对边界点定义。
readonly attribute Node startContainer;
readonly attribute long startOffset;
readonly attribute Node endContainer;
readonly attribute long endOffset;
 提供访问文档dom的高层次接口,每个操作和DOM
Core 的一系列方法对应,允许浏览器对常用的编辑模
式进行优化。
位置
 一个range包含两个边界点,分别用来标志range的开
始和结束位置。
 边界点可以用容器和偏移来表示。
 容器:Element, Comment, ProcessingInstruction,
EntityReference, CDATASection, Document,
DocumentFragment, Attr, or Text node
 偏移量:相对容器的偏移(字数或者节点数)
偏移量
 1. 容器为 Attr, Document, DocumentFragment,
Element 或者 EntityReference node
 偏移量为当前位置以前的节点个数
 2. 容器为 characterData, Comment 或者
ProcessingInstruction node
 偏移量为当前位置以前的文字个数
图解
API
 setStart() / setEnd()
 Collpase()
 selectNode() / selectNodeContents()
 deleteContents()
 …..
IE Range
 没有显示定义四个成员表示边界位置!
 API
API
 moveToElementText (Node a) :将选择区域变更为
a ,起始位置为 a 的前后。
 | <span> test </span> |
 collapse(start) :根据参数将结束位置重合到开始位
置(true)或开始位置重合到结束位置(false)。
 | <span> test </span> |
 ^ <span> test </span>
API
 parentElement :获取包围选择区域的元素节点。
 <span> te ^ st </span>
 range1.compareEndPoints('XxToYy',range2) :
 xx,yy 可以为 Start 或 End,取 range1 的 xx 位置和
range2 的 yy 位置比较,根据前后顺序返回-1,1,0表示
重合。
API
 range1.setEndPoint ( "XxToYy" , range2 ) :
 xx,yy 可以为 Start 或 End,将range1的xx位置设为
range2的yy位置。
 text :
 该选择区域内的文字信息
IE -> W3C
其他
 设置
 W3c
 r=document.createRange()
 r.setStart() / r.setEnd()
 s=window.getSelection
 s.removeAllRanges()
 s.addRange()
 IE
 Trick ?
回顾
See you next time

Contenu connexe

En vedette

设计好的用户体验 郑磊
设计好的用户体验 郑磊设计好的用户体验 郑磊
设计好的用户体验 郑磊麦哥UE
 
从钢铁侠与美国队长看用户体验
从钢铁侠与美国队长看用户体验从钢铁侠与美国队长看用户体验
从钢铁侠与美国队长看用户体验麦哥UE
 
Plan For Accessibility - TODCon 2008
Plan For Accessibility - TODCon 2008Plan For Accessibility - TODCon 2008
Plan For Accessibility - TODCon 2008Denise Jacobs
 
The Creativity (R)Evolution - UX Israel Studio 2014
The Creativity (R)Evolution - UX Israel Studio 2014The Creativity (R)Evolution - UX Israel Studio 2014
The Creativity (R)Evolution - UX Israel Studio 2014Denise Jacobs
 
Specialise or cross-skill
Specialise or cross-skillSpecialise or cross-skill
Specialise or cross-skillRuss Weakley
 
Streem - Water footprint, behavior and awareness
Streem - Water footprint, behavior and awarenessStreem - Water footprint, behavior and awareness
Streem - Water footprint, behavior and awarenessRobert Nyman
 
The Creativity Imperative - NDC London 2014
The Creativity Imperative - NDC London 2014The Creativity Imperative - NDC London 2014
The Creativity Imperative - NDC London 2014Denise Jacobs
 
21 Hacks For Self-Confidence
21 Hacks For Self-Confidence21 Hacks For Self-Confidence
21 Hacks For Self-ConfidenceBarrie Davenport
 

En vedette (9)

设计好的用户体验 郑磊
设计好的用户体验 郑磊设计好的用户体验 郑磊
设计好的用户体验 郑磊
 
从钢铁侠与美国队长看用户体验
从钢铁侠与美国队长看用户体验从钢铁侠与美国队长看用户体验
从钢铁侠与美国队长看用户体验
 
Plan For Accessibility - TODCon 2008
Plan For Accessibility - TODCon 2008Plan For Accessibility - TODCon 2008
Plan For Accessibility - TODCon 2008
 
The Creativity (R)Evolution - UX Israel Studio 2014
The Creativity (R)Evolution - UX Israel Studio 2014The Creativity (R)Evolution - UX Israel Studio 2014
The Creativity (R)Evolution - UX Israel Studio 2014
 
Specialise or cross-skill
Specialise or cross-skillSpecialise or cross-skill
Specialise or cross-skill
 
DO GOOD (Better)
DO GOOD (Better)DO GOOD (Better)
DO GOOD (Better)
 
Streem - Water footprint, behavior and awareness
Streem - Water footprint, behavior and awarenessStreem - Water footprint, behavior and awareness
Streem - Water footprint, behavior and awareness
 
The Creativity Imperative - NDC London 2014
The Creativity Imperative - NDC London 2014The Creativity Imperative - NDC London 2014
The Creativity Imperative - NDC London 2014
 
21 Hacks For Self-Confidence
21 Hacks For Self-Confidence21 Hacks For Self-Confidence
21 Hacks For Self-Confidence
 

Similaire à Range介绍

Kissy editor开发与设计
Kissy editor开发与设计Kissy editor开发与设计
Kissy editor开发与设计yiming he
 
Kindeditor设计思路v2
Kindeditor设计思路v2Kindeditor设计思路v2
Kindeditor设计思路v2luolonghao
 
Ecma script edition5-小试
Ecma script edition5-小试Ecma script edition5-小试
Ecma script edition5-小试lydiafly
 
Real World ASP.NET MVC
Real World ASP.NET MVCReal World ASP.NET MVC
Real World ASP.NET MVCjeffz
 
ES5 introduction
ES5 introductionES5 introduction
ES5 introductionotakustay
 
Kind editor设计思路
Kind editor设计思路Kind editor设计思路
Kind editor设计思路taobao.com
 
函数调用关系工具-2011-孙光福
函数调用关系工具-2011-孙光福函数调用关系工具-2011-孙光福
函数调用关系工具-2011-孙光福Wu Liang
 
Kindeditor 设计思路
Kindeditor 设计思路Kindeditor 设计思路
Kindeditor 设计思路luolonghao
 
107个常用javascript语句 oss 计算技术 - ossez info of tech
107个常用javascript语句   oss 计算技术 - ossez info of tech107个常用javascript语句   oss 计算技术 - ossez info of tech
107个常用javascript语句 oss 计算技术 - ossez info of techYUCHENG HU
 
Mongo db技术分享
Mongo db技术分享Mongo db技术分享
Mongo db技术分享晓锋 陈
 
非常靠谱 Html 5
非常靠谱 Html 5 非常靠谱 Html 5
非常靠谱 Html 5 Tony Deng
 
Web testing automation
Web testing automationWeb testing automation
Web testing automationkuozui
 
J2ee经典学习笔记
J2ee经典学习笔记J2ee经典学习笔记
J2ee经典学习笔记yiditushe
 
钱宝坤:多浏览器集成的JavaScript单元测试工具
钱宝坤:多浏览器集成的JavaScript单元测试工具钱宝坤:多浏览器集成的JavaScript单元测试工具
钱宝坤:多浏览器集成的JavaScript单元测试工具taobao.com
 
ASP.NET Core 2.1設計新思維與新發展
ASP.NET  Core 2.1設計新思維與新發展ASP.NET  Core 2.1設計新思維與新發展
ASP.NET Core 2.1設計新思維與新發展江華 奚
 
Google protocol buffers简析
Google protocol buffers简析Google protocol buffers简析
Google protocol buffers简析wavefly
 
3 hibernate映射元素和类型
3 hibernate映射元素和类型3 hibernate映射元素和类型
3 hibernate映射元素和类型Zelin Wang
 

Similaire à Range介绍 (20)

Kissy editor开发与设计
Kissy editor开发与设计Kissy editor开发与设计
Kissy editor开发与设计
 
Kindeditor设计思路v2
Kindeditor设计思路v2Kindeditor设计思路v2
Kindeditor设计思路v2
 
Hibernate教程
Hibernate教程Hibernate教程
Hibernate教程
 
Hibernate
HibernateHibernate
Hibernate
 
Ecma script edition5-小试
Ecma script edition5-小试Ecma script edition5-小试
Ecma script edition5-小试
 
Real World ASP.NET MVC
Real World ASP.NET MVCReal World ASP.NET MVC
Real World ASP.NET MVC
 
ES5 introduction
ES5 introductionES5 introduction
ES5 introduction
 
Kind editor设计思路
Kind editor设计思路Kind editor设计思路
Kind editor设计思路
 
函数调用关系工具-2011-孙光福
函数调用关系工具-2011-孙光福函数调用关系工具-2011-孙光福
函数调用关系工具-2011-孙光福
 
Kindeditor 设计思路
Kindeditor 设计思路Kindeditor 设计思路
Kindeditor 设计思路
 
107个常用javascript语句 oss 计算技术 - ossez info of tech
107个常用javascript语句   oss 计算技术 - ossez info of tech107个常用javascript语句   oss 计算技术 - ossez info of tech
107个常用javascript语句 oss 计算技术 - ossez info of tech
 
Mongo db技术分享
Mongo db技术分享Mongo db技术分享
Mongo db技术分享
 
非常靠谱 Html 5
非常靠谱 Html 5 非常靠谱 Html 5
非常靠谱 Html 5
 
Web testing automation
Web testing automationWeb testing automation
Web testing automation
 
J2ee经典学习笔记
J2ee经典学习笔记J2ee经典学习笔记
J2ee经典学习笔记
 
钱宝坤:多浏览器集成的JavaScript单元测试工具
钱宝坤:多浏览器集成的JavaScript单元测试工具钱宝坤:多浏览器集成的JavaScript单元测试工具
钱宝坤:多浏览器集成的JavaScript单元测试工具
 
J Query Learn
J Query LearnJ Query Learn
J Query Learn
 
ASP.NET Core 2.1設計新思維與新發展
ASP.NET  Core 2.1設計新思維與新發展ASP.NET  Core 2.1設計新思維與新發展
ASP.NET Core 2.1設計新思維與新發展
 
Google protocol buffers简析
Google protocol buffers简析Google protocol buffers简析
Google protocol buffers简析
 
3 hibernate映射元素和类型
3 hibernate映射元素和类型3 hibernate映射元素和类型
3 hibernate映射元素和类型
 

Plus de yiming he

kissy 1.5 progress
kissy 1.5 progresskissy 1.5 progress
kissy 1.5 progressyiming he
 
kissy at alibaba
kissy at alibabakissy at alibaba
kissy at alibabayiming he
 
kissy modularization part2
kissy modularization part2kissy modularization part2
kissy modularization part2yiming he
 
kissy modularization part1
kissy modularization part1kissy modularization part1
kissy modularization part1yiming he
 
KISSY @ 2013-2
KISSY @ 2013-2KISSY @ 2013-2
KISSY @ 2013-2yiming he
 
KISSY 1.4.0 released
KISSY 1.4.0 releasedKISSY 1.4.0 released
KISSY 1.4.0 releasedyiming he
 
callSuper in kissy
callSuper in kissycallSuper in kissy
callSuper in kissyyiming he
 
KISSY XTemplate
KISSY XTemplateKISSY XTemplate
KISSY XTemplateyiming he
 
Introduction to kissy for adc 2013
Introduction to kissy for adc 2013Introduction to kissy for adc 2013
Introduction to kissy for adc 2013yiming he
 
Kissy component system
Kissy component systemKissy component system
Kissy component systemyiming he
 
KISSY@2013.05
KISSY@2013.05KISSY@2013.05
KISSY@2013.05yiming he
 
kissy@2013.03
kissy@2013.03 kissy@2013.03
kissy@2013.03 yiming he
 
KISSY 1.3-released
KISSY 1.3-releasedKISSY 1.3-released
KISSY 1.3-releasedyiming he
 
Simple kissy1.3
Simple kissy1.3Simple kissy1.3
Simple kissy1.3yiming he
 
Kissy in-progress
Kissy in-progressKissy in-progress
Kissy in-progressyiming he
 
Kissy dpl-practice
Kissy dpl-practiceKissy dpl-practice
Kissy dpl-practiceyiming he
 
编辑器设计2
编辑器设计2编辑器设计2
编辑器设计2yiming he
 
KISSY Editor Design 2
KISSY Editor Design 2KISSY Editor Design 2
KISSY Editor Design 2yiming he
 

Plus de yiming he (20)

kissy 1.5 progress
kissy 1.5 progresskissy 1.5 progress
kissy 1.5 progress
 
kissy at alibaba
kissy at alibabakissy at alibaba
kissy at alibaba
 
kissy modularization part2
kissy modularization part2kissy modularization part2
kissy modularization part2
 
kissy modularization part1
kissy modularization part1kissy modularization part1
kissy modularization part1
 
KISSY @ 2013-2
KISSY @ 2013-2KISSY @ 2013-2
KISSY @ 2013-2
 
KISSY 1.4.0 released
KISSY 1.4.0 releasedKISSY 1.4.0 released
KISSY 1.4.0 released
 
callSuper in kissy
callSuper in kissycallSuper in kissy
callSuper in kissy
 
KISSY XTemplate
KISSY XTemplateKISSY XTemplate
KISSY XTemplate
 
Introduction to kissy for adc 2013
Introduction to kissy for adc 2013Introduction to kissy for adc 2013
Introduction to kissy for adc 2013
 
Kissy component system
Kissy component systemKissy component system
Kissy component system
 
KISSY@2013.05
KISSY@2013.05KISSY@2013.05
KISSY@2013.05
 
kissy@2013.03
kissy@2013.03 kissy@2013.03
kissy@2013.03
 
kissy@2013
kissy@2013kissy@2013
kissy@2013
 
KISSY 1.3-released
KISSY 1.3-releasedKISSY 1.3-released
KISSY 1.3-released
 
Simple kissy1.3
Simple kissy1.3Simple kissy1.3
Simple kissy1.3
 
Hujs 总结
Hujs 总结Hujs 总结
Hujs 总结
 
Kissy in-progress
Kissy in-progressKissy in-progress
Kissy in-progress
 
Kissy dpl-practice
Kissy dpl-practiceKissy dpl-practice
Kissy dpl-practice
 
编辑器设计2
编辑器设计2编辑器设计2
编辑器设计2
 
KISSY Editor Design 2
KISSY Editor Design 2KISSY Editor Design 2
KISSY Editor Design 2
 

Range介绍