如果想要修改文本范围的延展范围,可以使用 move, moveToElementText 和 findText 移动其起始和终止位置。在文本范围内,你可以获取并修改纯文本或 HTML 文本。这些格式的文本完全相同,只是 HTML 文本包含 HTML 标签,而纯文本不包含。
下面的例子通过 TextRange 对象将 button 元素的文本更改为“已单击”。
<SCRIPT LANGUAGE="JScript">
var b = document.all.tags("BUTTON");
if (b!=null) {
var r = b[0].createTextRange();
if (r != null) {
r.text = "已单击";
}
}
</SCRIPT>
W3C standard description
http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html
Microsoft documentation
Creates a TextRange object from the current text selection, or a controlRange collection from a control selection.
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods/createrange.asp
For the properties and methods of the control range object, visit http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/mshtml/reference/ifaces/controlrange/controlrange.asp
For the properties and methods of the text range object, visit http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/obj_textrange.asp