document.selection.createRange方法:
document.selection.createRange() 根据当前文字选择返回 TextRange 对象,或根据控件选择返回 ControlRange 对象。配合 execCommand,在 HTML 编辑器中很有用,比如:文字加粗、斜体、复制、粘贴、创建超链接等。
一个简单的例子
<html><head><title>document.selection.createRange例子</title></head><body>
<div>请选中这里的部分文字。</div><div><input type="button" value="加粗" onclick="javascript :Bold();" /></div>
<script language="javascript">
function Bold(){
var bo = document.selection.createRange();
bo.execCommand("Bold");
}</script>
</body></html>