跳到主要内容

MoveCursorToPos

将光标移动到当前范围对象的指定位置。 如果文档中有任何选区,它将被移除。

语法

expression.MoveCursorToPos(nPos);

expression - 表示 ApiRange 类的变量。

参数

名称必需/可选数据类型默认值描述
nPos可选number0所需的光标位置。

返回值

boolean

示例

将光标移动到文档中文本范围内的特定位置。

// How do I place the cursor at a chosen location inside a range in a document?

// Reposition the cursor to reach a particular spot within selected text in a document.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
paragraph.AddText("This text for time field");
let range = paragraph.GetRange();
range.MoveCursorToPos(range.GetEndPos());
paragraph = Api.CreateParagraph();
paragraph.AddText("The cursor was moved to the end of range");
doc.Push(paragraph);