理解setEndPoint方法

 

理解setEndPoint方法

今天在修改控件时,使用到了setEndPoint方法,查找了MSDN,自己测试了一下,总结了该方法的使用,供大家分享。
MSDN
上的解释是:

Sets the endpoint of one range based on the endpoint of another range.

表面意思是:在另一个rangeendpoint基础上设置某个rangeendpoint.

基本概念:

A text range has two endpoints: one at the beginning of the text range and one at the end. An endpoint can also be the position between two characters in an HTML document.

一个text range包含两个endpoints,一个在text range的开头,另一个在text range的末尾。一个endpoint也可以在HTML文档的两个字符之间。

Syntax:

TextRange.setEndPoint(sType, oTextRange)

Parameters

sType

Required. String that specifies the endpoint to transfer using one of the following values.

StartToEnd

Move the start of the TextRange object to the end of the specified oTextRange parameter.

StartToStart

Move the start of the TextRange object to the start of the specified oTextRange parameter.

EndToStart

Move the end of the TextRange object to the start of the specified oTextRange parameter.

EndToEnd

Move the end of the TextRange object to the end of the specified oTextRange parameter.

oTextRange

Required. TextRange object from which the source endpoint is to be taken.

Return Value

No return value.

举例:

//123被选中

var workRange=document.selection.createRange();

var allRange=obj.createTextRange();//obj指代文本框实例

情况一:

workRange.setEndPoint("StartToStart",allRange);

workRange.text => 0123

情况二:

workRange.setEndPoint("EndToStart",allRange);

workRange.text => 0

情况三:

workRange.setEndPoint("StartToEnd",allRange);

workRange.text => 456789

情况四:

workRange.setEndPoint("EndToEnd",allRange);

workRange.text => 123456789

解释:

情况一:

workRange.text初始值为123,两个endpoints分别位于01之间、34之间。我们简称01之间的endpointepStart34之间的endpointepEnd,理解执行结果的核心是理解workRange.setEndPoint方法的第一个参数。同时,我们需要理解的一点就是allRange也存在两个endpoints,分别位于0之前、9之后。我们简称这两个endpoints分别为allRange_epStartallRange_epEnd

StartToStart英文解释是:Move the start of the TextRange object to the end of the specified oTextRange parameter.

在本例中,也就是指:将workRangeepStart移动到allRangeallRange_epStart,那么workRange的文本变为allRange_epStartepEnd范围之间。AllRange_epStart成为了workRangeepStart。情况二、三、四的解释类似,就不啰唆了。

转载于:https://www.cnblogs.com/kakaxu/archive/2007/12/23/1011683.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值